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

Re: find and replace text in files



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





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