String replacement for all files in directory

H.S. hs.samix at
Sat Nov 29 05:36:34 UTC 2008

Kipton Moravec wrote:
> How do I do a simple string replacement of one string with another
> string in all files in a directory?
> For example:
> I have 1200 files in a directory. Wherever I see the string
> "footprint=0603C" in any of the files (may occur 0 or multiple times) I
> want to replace with "footprint=CAPC0603N"
> I do not know how to figure out what command to use so I can look it up.
> Kip  

Using perl (untested):
$> perl -p -i -e "s/0603C/CAPC0603N/g;"  *

The above command will replace 0603C with CAPC0603N in all files (due to
"*") in the current directory.

If you want to be a bit safe, use:
$> perl -p -i.backup -e "s/0603C/CAPC0603N/g;"  *

This will do the same, but the original version of the files will be
saved in the original filename but with ".backup" added to it. If the
replacements are good, you can remove all *.backup files in the directory.



Please reply to this list only. I read this list on its corresponding
newsgroup on Replies sent to my email address are just
filtered to a folder in my mailbox and get periodically deleted without
ever having been read.

More information about the ubuntu-users mailing list