[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [cobalt-developers] find and replace shell script
- Subject: Re: [cobalt-developers] find and replace shell script
- From: "Dale P. Smith" <dsmith@xxxxxxxxxxxxx>
- Date: Fri Apr 5 05:53:15 2002
- Organization: Altus Technologies Corporation
- List-id: Discussion Forum for developers on Sun Cobalt Networks products <cobalt-developers.list.cobalt.com>
On Thu, 04 Apr 2002 12:08:21 -0800
Bruce Timberlake <bruce.timberlake@xxxxxxx> wrote:
> Matthew Nuzum wrote:
> >
> > Can anyone suggest a command that I can use in a shell script that will
> > help me do a find and replace action on a couple of thousand XML files?
> >
> > I need to replace something like http://domain.com/images with just
> > /images and it can occur several times in the same file.
> >
> > Unfortunately, due to the nature of XML, many of the files don't contain
> > a single carriage return, just one very long line.
>
> I tried posting this a couple of days ago, but it never showed up.
> Second try...
>
> cat file.xml | sed "s/oldstring/newstring/g" > newfile.xml
>
> so for your specific string, you'd have to use some "\" to escape the
> regular slashes, etc, and end up with:
But with sed, you are not limited to / chars for delimiters.
> cat file.xml | sed "s/http\:\/\/domain\.com\/images/\/images/g" >
> newfile.xml
sed 's|http://domain.com/images|/images|g' < file.xml > newfile.xml
-Dale
--
Dale P. Smith
Treasurer, Cleveland Linux Users Group http://cleveland.lug.net
Senior Systems Consultant, Altus Technologies Corporation
dsmith@xxxxxxxxxxxxx
440-746-9000 x339