2005/11/15, Gabriel Briones <[EMAIL PROTECTED]>:
> sed can do the trick
>
> sed -e 's/foo/bar/g' file.txt > new_file.txt
>
> the above command will replace all the existence of foo with bar on
> file.txt and will redirect the modified output to new_file.txt

Well the OP did say hundreds of files, so a little more work is
necessary. For the GNU version of sed (which should be available in
all GNU/Linux distributions but probably not in OSX) I'd do something
like:

find /Directory/Subdirectory -name "*.txt" \
  | xargs sed --in-place=.bak 's/foo/bar/g'

With the proper options, the "find" command will create a list of
files you want to change (e.g. only *.txt or *.html) and pass (or
pipe) this list to "sed" via the special utility "xargs".

The "--in-place" or "-i" option tells sed to change the file itself
rather than just have the changes output to the screen or redirected
to a file. The added "=.bak" will create a backup of the changed
file(s) with the extension .bak.

(Note: the "--in-place" may not be available in all versions of GNU
sed. Also, you could replace xargs with the built-in "-exec" or
"-execdir" options of find)

> On 11/15/05, Che Sosa <[EMAIL PROTECTED]> wrote:
> > Mabuhay PLUG members,
> >
> > I have a problem of parsing text. What I want is to parse certain
> > sequences from hundreds of files and replace them with a certain
> > pattern of text.
> >
> > Is this doable with sh? What tools/programming languages is suitable for 
> > this?
_________________________________________________
Philippine Linux Users' Group (PLUG) Mailing List
[email protected] (#PLUG @ irc.free.net.ph)
Read the Guidelines: http://linux.org.ph/lists
Searchable Archives: http://archives.free.net.ph

Reply via email to