Home > Enterprise >  merge every two consecutive lines unix?
merge every two consecutive lines unix?

Time:10-18

hi i need your help in unix ,

how i can merge every two consecutive lines unix in a file ,

Reservoir
Dogs
1992
reviewed
by
Michael
Hareven

i need the out but like

Reservoir  Dogs
Dogs       1992
1992       reviewed
reviewed   by
by         Michael
Michael.   Hareven
  • List item

i tried this code awk 'NR%2?ORS=FS:ORS=RS' but it give me like AB CD if some could help me

i tried this code awk 'NR%2?ORS=FS:ORS=RS' but it give me like AB CD if some could help me i tried this code awk 'NR%2?ORS=FS:ORS=RS' but it give me like AB CD if some could help me

CodePudding user response:

On the first line, save its value, and then for each subsequent line, print the previous saved value and the current text, and then replace the saved text with the current line:

$ awk 'NR == 1 { prev = $0; next }
       { print prev, $0; prev = $0 }' input.txt
Reservoir Dogs
Dogs 1992
1992 reviewed
reviewed by
by Michael
Michael Hareven
  •  Tags:  
  • unix
  • Related