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

inserting a carriage return to a text file from a unix shell script

Status
Not open for further replies.

edwardb15

Technical User
Mar 23, 2004
10
AU
i am writing a bourne shell script to append to each line in a text file a return character (new line) then followed by 'go'

using:

#!/bin/sh
cat ${format_file_name}.out | /bin/sed -e 's/$/^Mgo/g' > junk.lst

example of row in file ${format_file_name}.out:
table1
table2
table3

using <ctrl v><ctrl M> for the return character.

whats happening to output file junk.lst is
table1^Mgo
table2^Mgo
table3^Mgo

wanting to achieve:
table1
go
table2
go
table3
go

not inserting a new row. any help would be appreciated.
thanks.

 
sed 'G;s/\n/&go/' ${format_file_name}.out > junk.lst

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
The awk way:
awk '
$0!="go"{print;print "go"}
'${format_file_name}.out > junk.lst

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top