Search/Replace in many Files
example of how to run a search
and replace through many files in UNIX. Comes in handy for situations like
when Netscape Composer changes all the links to absolute rather than relative.
from the unix command prompt:
- type foreach file (*.html)
where *.html is the search pattern
- there will be a new prompt. Type:
- cp $file $file.orig
to backup the files
- mv $file xx
which moves the old files into a 'temp' file
- sed '1,$s/search/replace/g' xx > $file
where search and replace are your strings.
- Note: Special characters
such as / should be preceded by a \
- end
- Once you type 'end', it will execute
these commands.