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!

Using sed within a shell script

Status
Not open for further replies.

jprabaker

Technical User
May 31, 2001
185
GB
Hi,

I'm new to using sed. I'm trying to create a simple sed command in my script to search a file by a unix variable and then append text to matching lines. I've tried:

more filename |sed '/$VARIABLE/s/ *$/appended text'

but this doesn't seem to do anything.

Could someone advise?

Regards,
 
Your single quotes in the sed command are stopping the variable being interpreted.

To illustrate, try this:

x='abc'
print "$x"
print '$x'

Try double quotes in your command and see how you go. Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
 
The *$ is matching the whole line. You only want to match the end of the line. Try this.

sed -e"/$MYVAR/s/$/#comment/" file > newfile
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top