Reputation: 13
I would like to convert first 2 lines to first row and next 2 lines to second row and so on. Could someone help me? .would it possible to do by awk command.
File.txt has the below entries
Bin1
Bin2
Hex3
Hex4
oct5
oct6
I would like to get output as below
Bin1 Bin2
Hex3 Hex4
oct5 oct6
Upvotes: 1
Views: 74
Reputation: 203219
$ awk '{ORS=(NR%2?FS:RS)}1' file
Bin1 Bin2
Hex3 Hex4
oct5 oct6
Upvotes: 1
Reputation: 85775
You could just use xargs
:
$ xargs -n2 < file
Bin1 Bin2
Hex3 Hex4
oct5 oct6
Or paste
:
$ paste -d' ' - - < file
Bin1 Bin2
Hex3 Hex4
oct5 oct6
Upvotes: 1
Reputation: 40718
You can try:
awk 'NR%2{printf "%s%s",$0,OFS}NR%2==0' file
Output:
Bin1 Bin2
Hex3 Hex4
oct5 oct6
Upvotes: 1