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

Insert a new line with text using sed

Status
Not open for further replies.

dsm325

Technical User
Apr 4, 2001
29
US
I have several hundered files with the exact same format, and I need to add a line below another line that starts with
SENDID.
My new line will have RESOURCE=10030

I tried playing with i ((insert) and I am not coming up with anything.

Please assist, thanks much
 
Try something like this:
Code:
sed -e '/^SENDID/iRESOURCE=10030
' /path/to/oldfile >/path/to/newfile

Hope This Help
PH.
 
I have several files that need to be changed, do I put some kind of a loop?
 
Says you have a file FileNames.lst with the list of the files to changed, you can do something like this:
Code:
while read f
do sed -e '/^SENDID/iRESOURCE=10030
' "$f" >"$f.tmp" && mv "$f.tmp" "$f"
done </path/to/FileNames.lst

Hope This Help
PH.
 
PH thanks for taking the time to help me out with this.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top