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

One Liner - Insert Text in File

Status
Not open for further replies.

simpson

MIS
Oct 23, 2001
58
0
0
CA
All,

I am looking for a one-liner to insert text into an ascii file above a line that matches a search.

Example.
I would like to insert a line of text above the line End_of_Section in a file.

Before:

file_a
-------
Start_of_Section
mike
julie
spencer
End_of_Section

After:
file_a
-------
Start_of_Section
mike
julie
spencer
dave
End_of_Section

I would prefer to do this with a one liner. Thanks in advance.
Mike

 
Thanks,

I acutally have this one bookmarked along side my Awk one liners and Perl one liners. I just can't seem to solve this "simple looking" problem.
 
Perhaps not technically a one-liner due to the embedded carriage return, but this is just a straightforward application of the sed insert command:

Code:
sed '/End_of_Section/i\
dave' file_A

Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top