Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 24 Dec 2006 02:56:32 -0500
From:      Parv <parv@pair.com>
To:        Josh Paetzel <josh@tcbug.org>
Cc:        Jack Stone <antennex@hotmail.com>, freebsd-questions@freebsd.org
Subject:   Re: Search & Replace Issue
Message-ID:  <20061224075632.GB97940@holestein.holy.cow>
In-Reply-To: <200612232230.58352.josh@tcbug.org>
References:  <BAY125-F30049BC3F42C8F2E17BA61CCC30@phx.gbl> <200612232230.58352.josh@tcbug.org>

next in thread | previous in thread | raw e-mail | index | archive | help
in message <200612232230.58352.josh@tcbug.org>,
wrote Josh Paetzel thusly...
>
> On Saturday 23 December 2006 21:29, Jack Stone wrote:
> > Appreciate a tip on how to search & replace  hundreds of *.htm
> > files:
> > >From this:
> >
> > <li><a href="http://www.domain.com/tales/wouf.html
> > To this:
> > <li><a href="tales/wouf.html
> >
> 
> perl -p0777i -e 's/http:\/\/www.domain.com\///g' *.htm

Is -0777 really necessary (causes whole file to be stored in
memory)?  But that is not really the point of this reply.

Above is a fine opportunity to use alternative delimiters (and to
restrict the matching (only to link URLs)) ...

  perl -pi -e 's!(?<=href=")\Qhttp://www.domain.com!!g' *.html


... in case of "hundreds of *.htm", use xargs(1) pipeline ...

  find  dir-of-HTML-files  -type f -name '*.html' -print0 \
  | xargs -0 perl -pi -e 's!(?<=href=")\Qhttp://www.domain.com!!g'


Feel free to change Perl version with sed (the version of sed with
-i option[0]) one ...

  find ... \
  | ... sed -i -e 's,\(href="\)http://www\.domain\.com,\1,g'


  [0] That makes this reply on point.


  - Parv

-- 




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