Operating System - HP-UX
1838483 Members
3461 Online
110126 Solutions
New Discussion

Re: replace string in files

 
Joe Steele
Occasional Advisor

replace string in files

used to replace a certain string in a file-list. basically just provides a shell for sed - for the leyman user.
2 REPLIES 2
Tom Jackson
Valued Contributor

Re: replace string in files

Hi try this ->

for i in `ls /somedir`
do
sed -e s/oldstring/newstring/ ${i} > ${i}.tmp
mv ${i}.tmp ${i}
done

Note that the for statement uses the glitch key located above the tab key.

hth,
Tom
Bill Hassell
Honored Contributor

Re: replace string in files

The glitch key (aka, reverse apostrophe or grave accent) is considered to be obsolete (archaic in man-speak). A better way for command substitution (and far less likely to be mis-typed) is the $(command-list) format as in:

for i in $(ls /somedir)

This is especially helpful with non-English keyboards or with faxes that are a bit dusty.


Bill Hassell, sysadmin