Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Merging every second line with previous

Status
Not open for further replies.

Zahier

MIS
Oct 3, 2002
97
ZA
Hi,

I have an input file:

aaaaaa
bbbbbb
cccccc
dddddd
eeeeee
ffffff

I'm trying to use awk to merge the lines so they'll look like:

aaaaaabbbbbb
ccccccdddddd
eeeeeeffffff

Please help :)
 
Code:
awk '{ getline b ; print $0 b }' file

--
 
Hi,

When I run :
awk '{ getline b ; print $0 b }' file
on a SUN OS it gives different results:

bbbbbb
dddddd
ffff

instead of:
aaaaaabbbbbb
ccccccdddddd
eeeeeeffffff

Is awk not compatible on all Unix/Linux boxes?
 
Try using nawk

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Code:
awk '{printf("%s%s", $0, (FNR%2) ? "" : "\n")}' file

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top