unix - Replacing alternate spaces with newline? -
i trying replace alternate spaces newlines using unix. tried using tr command in unix unable modify replace alternate spaces.
sample input:
0 1 2 3 4 5
sample output:
0 1
2 3
4 5
how achieve ?
awk
might in case:
echo "0 1 2 3 4 5" | awk ' { (i=1; i<=nf; i++) { if ((i-1)%2 == 0) { printf "%d ",$i; } else { print $i } } } '
we split space , have 6 items. we, then, looping through fields , outputting each field. every other field output in new line print $i
; otherwise print using printf "%d ",$i;
, not create new line.
Comments
Post a Comment