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

simple sed problem

Status
Not open for further replies.

redsevens

IS-IT--Management
Aug 11, 2000
40
US
I am using sed in a script to edit several hundred files. I want to basically do a search and replace, but the search uses wildcards. The replace is the same for each file.

For example, most files contain the line
Code:
Return_Address=[i]zero or more characters[/i]
and I want them all to be changed to:
Code:
Return_Address=customer_service@myhost.com

I initially tried the following script:
Code:
instring='Return_Address=*\n';
outstring='Return_Address=customer_service@myhost.com\n';
for i in `ls *.ini`
do
   cat $i | sed s/$instring/$outstring/g > new_inis/$i;
done

This causes no errors, but doesn't change the files. Does anybody know what I'm missing?
 

instring='Return_Address=';
address='customer_service@myhost.com\n';
for i in `ls *.ini`
do
cat $i | sed -e "s/${instring}/${instring}${address}/g" > new_inis/$i;
done
 
Use .* instead of *\n in your search string and remove the \n from your replace string.

Hope this helps. CaKiwi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top