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

how to use line feed separator in awk

Status
Not open for further replies.

Arpa

Programmer
Apr 6, 2001
4
FR
I need to format a file where records are separated by only Linefeed (0a). I tryed several solutions which doesn't
works.

1) echo "a" | awk 'BEGIN{ORS="\x0a" } {print "xxx";print"yyy"}' > toto
Result: 78 78 78 0d 0a 79 79 79 0d 0a => Carriage return (0d) is unexpected

2 ) echo "a" | awk '{printf("xxx\x0ayyy")'} > toto
Result: 78 78 78 0d 0a 79 79 79 => Carriage return (0d) is unexpected

How to get a result as 78 78 78 0a 79 79 79 ?
 
Arpa-

Try this:

echo "a" | awk 'BEGIN{RS = ORS = "\n"}{print "xxx";print "yyy"}' > toto

It looks like you need to set both to a newline in
the BEGIN statement. Works on a Sun Solaris box.

Hope this helps.


flogrr
flogr@yahoo.com

 
Thanks for your help but ... it doesn't work on my environment (NT + Gnu)
The result is 78 78 78 0d 0a 79 79 79 instead of 78 78 78 0a 79 79 79.
 
Arpa-

Since you are on the NT system and windows uses
a carriage return followed by a newline instead
of the Unix newline you are pretty much stuck with
the output you are getting. The awk script is
working properly for the platform you are on.

I doubt there is any way to force only linefeeds
on a windows machine.

Regards,





flogrr
flogr@yahoo.com

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top