Re: find and replace text in files

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

 



Hi,

Good answer, but if your want to replace all "search" terms in a line
(and not only the first found), just add the "g" parameter at the end of
sed command : (g = globally)...

for file in `ls` ; do cat $file | sed 's/search/replace/g' > $file.new ;
> done

If I make no mistake, as I did not use it for a long time, but used to
work with it in my former job.

Cheers,

-- 
Philippe, Chiangmai, Thailand




On Fri, 2003-03-28 at 21:35, Piero Calucci wrote:
> On Fri, 2003-03-28 at 15:15, ghwbush wrote:
> > I have a directory of about 60 files.  I want to search these files and 
> > replace some text.  Is there an easy way to do this from a command 
> > line?
> 
> for file in `ls` ; do cat $file | sed 's/search/replace/' > $file.new ;
> done
> 
> assuming you are searching for "search" and want to replace it with
> "replace"
> 
> Piero



-- 
Psyche-list mailing list
Psyche-list@xxxxxxxxxx
https://listman.redhat.com/mailman/listinfo/psyche-list

[Index of Archives]     [Fedora General Discussion]     [Red Hat General Discussion]     [Centos]     [Kernel]     [Red Hat Install]     [Red Hat Watch]     [Red Hat Development]     [Red Hat 9]     [Gimp]     [Yosemite News]

  Powered by Linux