Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 18 Dec 2001 12:02:56 +0100
From:      Erik Trulsson <ertr1013@student.uu.se>
To:        Jon Molin <Jon.Molin@resfeber.se>
Cc:        Anthony Atkielski <anthony@freebie.atkielski.com>, FreeBSD Questions <freebsd-questions@FreeBSD.ORG>
Subject:   Re: Command to make modifications on multiple files
Message-ID:  <20011218110256.GA1464@student.uu.se>
In-Reply-To: <3C1F1C07.79B38414@resfeber.se>
References:  <007701c187af$8b564d40$0a00000a@atkielski.com> <3C1F1C07.79B38414@resfeber.se>

next in thread | previous in thread | raw e-mail | index | archive | help
On Tue, Dec 18, 2001 at 11:35:51AM +0100, Jon Molin wrote:
> Anthony Atkielski wrote:
> > 
> > There is probably a UNIX command that allows me to replace strings in
> > multiple files all at once, but I can't remember what the name of it would
> > be, and this being UNIX, I'm sure the name is not the least bit intuitive.
> 
> no i bet you'd benefit copying them to NT and replacing them there, it's
> probaly  a perfect name like 'replace strings in multiple files.exe'
> that will do the trick for you. 

No need to be rude.  If you don't know the answer just don't bother
with snide comments like this.
It is a fact that command names in Unix are often not very intuitive.

> 
> 
> > Any suggestions on what command would do this?  Sort of like grep, but with
> > an option to replace a string as well as just finding it.

You might want to look at sed or awk or maybe perl.
Of these perl is probably the easiest to do it in.  (This is the cue
for somebody to jump in and say how evil perl is and that it is much
easier to do it in <other program>. :-) )

WIth perl you might do it something like: 
[Warning! Untested code follows!]

perl -pie 's/searchregex/replacestring/g' file1 file2 file3 

( The -p option tells perl to read one line at a time from the input
files, do the command, and output the result. The -i option tells perl
to do it inplace rather than writing to stdout, and -e tells perl that
the next argument is the actual code and not the name of a file
containing the code. )

For more information please read the documentation for perl, 'man perl'
is a good place to start.




-- 
<Insert your favourite quote here.>
Erik Trulsson
ertr1013@student.uu.se

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20011218110256.GA1464>