I must agree -- Perl is built for tasks like this (though Java's regexp
support should make this nearly as trivial, and a nice exercise for the
interested reader...)
Of course, there are issues with sed. If the last line of the file doesn't
end with a newline, it can be "swallowed." ...and 'in place' editing isn't
possible, so you need two statements:
sed -e 's:THIS TEXT:THAT TEXT:g' <orig >munged
mv munged orig
One note, the syntax in the attached Perl one-liner isn't quite right --
the filenames go *after* the expression, and the expression should end with
a 'g' in case THIS TEXT occurs more than once on a line.
perl -pi -e 's/THIS TEXT/THAT TEXT/g' *.orig
Also, be careful using the '-i' flag -- this says change the file
'in-place', so it might be a good idea to specify a file extension to save
the original file with:
perl -pi.BAK -e 's/THIS TEXT/THAT TEXT/g' *.orig
Here's a little cygwin shell session. (Please excuse the temp filename --
I always use barf, since I can see the contents with 'cat barf,' which is
wired directly to my warped humor core... ;-)
$ cat barf
hello there hello hello
$ perl -p -e 's/hello/hi/' barf
hi there hello hello
$ perl -p -e 's/hello/hi/g' barf
hi there hi hi
$ perl -pi.BAK -e 's/hello/hi/g' barf
$ ls barf*
barf barf.BAK
$ cat barf
hi there hi hi
$ cat barf.BAK
hello there hello hello
HTH.
-blair
Blair Wyman -- iSeries JVM -- (507) 253-2891
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"It is a sobering thought that when Mozart was my age,
he had been dead for two years." -- Tom Lehrer
Joseph Ottinger
<joeo@enigmastati To: "JDJList"
<[EMAIL PROTECTED]>
on.com> cc:
Subject: [jdjlist] Re: sed equiv
12/06/2002 12:44
PM
Please respond to
"JDJList"
... or a one-liner. Perl makes this sort of thing really easy.
See the perl docs, specifically the perlrun document:
perl -pi '*.orig' -e 's/THIS TEXT/THAT TEXT/' *
On Fri, 6 Dec 2002, Greg Nudelman wrote:
> Try the Perl reg exp. Just google for "perl replace in file" It should be
> like a 20-line script.
>
> Greg
>
> -----Original Message-----
> From: Jason Carlamere [mailto:[EMAIL PROTECTED]]
> Sent: Friday, December 06, 2002 10:12 AM
> To: JDJList
> Subject: [jdjlist] sed equiv
>
>
> I need to write a batch script for dos that opens a file in the script
and
> replaces a word
>
> for example
>
> The script finds [THIS TEXT] and replaces it with [THAT TEXT]
>
> for the unix and linux boxes I used sed but sed does not exist in dos and
>
> I can not install gnu's windows version on the boxes.. So does anyone
know
> of a command that does this
>
> -Jason
>
>
---------------------------------------------------------
Joseph B. Ottinger [EMAIL PROTECTED]
http://enigmastation.com IT Consultant
____________________________________________________
To change your JDJList options, please visit:
http://www.sys-con.com/java/list.cfm
Be respectful! Clean up your posts before replying
____________________________________________________
____________________________________________________
To change your JDJList options, please visit:
http://www.sys-con.com/java/list.cfm
Be respectful! Clean up your posts before replying
____________________________________________________