Re: Replacing text within a bunch of files

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

 



On Sat, Apr 10, 2004 at 11:55:24AM -0700, Chris wrote:
> I'm having a bit of a problem trying to figure out how to properly use 'sed' to
> do a global search and replace on a character string within ALL files in a
> directory and all its subdirectories.  The one-file-at-a-time method works fine,
> but obviously this needs to be looped to traverse all files and all
> subdirectories...
> 
> This is what I've tried:
> 
> sed -e 's/old_string/new_string/g'  foo1.txt > foo2.txt
> 
> and it works fine.  How can I loop it automatically through all
> file/subdirectories, though?

You should be able to use something like:

find -type f -exec ...
or
find -type f | xargs -n 1 ...
or
find -type f | xargs -n 1 replace old_string new_string --

The latter will do an inplace replacement.
[root@pe400 foo]# find -type f |xargs -n1  replace foostuff oldstuff --
./tmp/c converted
./a converted
./b converted

-- 
Ed Wilts, Mounds View, MN, USA
mailto:ewilts@xxxxxxxxxx
Member #1, Red Hat Community Ambassador Program


-- 
redhat-list mailing list
unsubscribe mailto:redhat-list-request@xxxxxxxxxx?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/redhat-list

[Index of Archives]     [CentOS]     [Kernel Development]     [PAM]     [Fedora Users]     [Red Hat Development]     [Big List of Linux Books]     [Linux Admin]     [Gimp]     [Asterisk PBX]     [Yosemite News]     [Red Hat Crash Utility]


  Powered by Linux