1828411 Members
3871 Online
109977 Solutions
New Discussion

joinin lines

 
SOLVED
Go to solution
Rinky
Advisor

joinin lines

Hi experts!
I want every 2nd and 3rd line in a file to be joined to the previous line using unix.
No perl commands please
EG: in my file:
Do
Not
Leave
Do
Take
Care

I need the output as:
Do Not Leave
Do Take Care

Plssssss help
2 REPLIES 2
Peter Nikitka
Honored Contributor
Solution

Re: joinin lines

Hi,

is awk OK?

awk 'NR%3==1 {str=$0}
NR%3==2 {str=str" "$0}
NR%3==0 {print str,$0}
END {if (NR%3) print str}' filename

This will even take care for incomplete fields at the end of a file.

mfG Peter
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"
Rinky
Advisor

Re: joinin lines

WOW!! Thanks Peter..
Exactly wat i wanted... full points to you..