Here is another noob question. I have a file like this
John 30 Mike 0.0786268 Tyson 0.114889 Gabriel 0.176072 Fiona 0.101895
I need to shift every second row to a new column so it should look like this
John 30 Mike 0.0786268 Tyson 0.114889 Gabriel 0.176072 Fiona 0.101895
I just now that awk 'NR%2==0'
will print every second row, could somebody suggest me how to shift them to a new column as above. Any help is most appreciated.
awk '{printf "%s%s",$0,(NR%2?FS:RS)}' file
Explanation:
printf
will not include a new line character at the end of line (unlike print
)(NR%2?FS:RS)
decides new line (RS) or field seperator (FS) based on NR%2
If your colmns should be seperated by \t
awk '{printf "%s%s",$0,NR%2?"\t":RS}'
xargs could do it, the command line is really short:
xargs -n2 < file
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With