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

Re: Command line search and replace



On Sun, Jan 07, 2001 at 06:12:54PM +0100, Michal F. Hanula wrote:

> On Mon, Jan 08, 2001 at 12:56:45AM +0800, csj wrote:
> > Is there a tool to do a search-and-replace from the command
> > line?  Something along the lines of:
> >
> > replace "string one" "string foo" files-to-process
> >
> > I find it a bit of a hassle to keep 100+ files open just to
> > change an ".html" to an ".htm." Note however that I intend to
> > use the tool on other text files besides runaway web pages,
> > such as processing a list of files to feed to tar.
> >
> Use something like
>
> for file in * do sed 's/replace this/by this/g' < $file >
> $file.tmp; mv $file.tmp $file; done
>
> (there probably _are_ errors, check man sh)

Hi,

For this task I have been using the shell scripts 'overwrite' and
'replace' on pages 154-155, Section 5.5 of 'The UNIX programming
environment' by Kernighan and Pike. I have copied these small
scripts into $HOME/bin and use them often.

Best,
Raghavendra.

-- 
N. Raghavendra <raghu@mri.ernet.in> |
Harish-Chandra Research Institute   | What foods these morsels be!
        GnuPG public key at:        |
http://riemann.mri.ernet.in/~raghu/ |



Reply to: