Re: recursively find/replace text in files

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> > hi..
> >
> > can't find my old solution to this!! need to know how to find/replace
> > 'text'
> > in files in a directory tree. i'd like to be able to either do all files,
> > or
> > all files of a specific extension
> >
> >  replace "foo" with "bar" in all files in the dir tree
> >  replace "foo" with "bar" in all (*.cpp) files in the dir tree
> 
> something like:
> 
> find . -type f -name "*.cpp" -exec sed -i 's/foo/bar/g' {} \;
> 
> --

perl also has a similar funcionality

find . -type f -name "*.cpp" -exec perl -pi -e 's/foo/bar/g' {} \;

This is also portable to standard UNIX systems with perl installed.
(standard UNIX sed has no -i option).
--
Nix


[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux