Join consequent lines in unix

Friday, December 28, 2012 , , , 1 Comments

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
There can be many solutions for this:
sed:
sed 'N;s/\n/ /g' yourfile
Awk:
awk '{if(NR%2!=0){p=""}else{p="\n"};printf $0" "p}' your_file
Paste:
paste - - file new_file
My pick is:
xargs -n2

1 comment:

  1. Dude! You win! I never thought of using xargs like that. Elegant.

    ReplyDelete