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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

deleting end of line character 2

Status
Not open for further replies.

bi

Technical User
Apr 13, 2001
1,552
US
I have a file that has alphanumeric characters on the odd-numbered lines and digits on the even numbered lines. I want the digits to be appended at the end of the previous line. For example, I want a file that has:

alphanum1
digit1
alphanum2
digit2

to instead be:
alphanum1 digit1
alphanum2 digit2

I have tried doing this with sed and tr, but can't seem to get it. I'm fairly new to both, and have made some good headway on earlier parts of the script I'm writing, but I just can't seem to get this.

Can someone help? Is there another command I should be using, like awk?

Thanks.
 
You could use awk

awk 'NR%2{printf $0;next}{print}' infile > outfile

CaKiwi

"I love mankind, it's people I can't stand" - Linus Van Pelt
 
OR:

nawk '{ printf("%s%s", $0, (NR % 2) ? " " : "\n")}' infile

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Thank you both. That's what I needed.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top