Join every two lines in a file

Sunday, December 30, 2012 , 0 Comments

If we have an input file like

1
2
3
4
5
6
7

How can we join every two lines so that the output will be:

1 2
3 4
5 6
7

Below is a very simple solution for this:

paste - - <your_file
awk:

awk '{if(NR%2==0){line=line" "$0;print line;}else{line=$0}}END{if(NR%2)print line}' your_file


0 comments: