From owner-freebsd-questions@FreeBSD.ORG Sun Dec 24 22:24:49 2006 Return-Path: X-Original-To: freebsd-questions@FreeBSD.ORG Delivered-To: freebsd-questions@FreeBSD.ORG Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id AB59316A5FD for ; Sun, 24 Dec 2006 22:24:49 +0000 (UTC) (envelope-from mike.jeays@rogers.com) Received: from smtp100.rog.mail.re2.yahoo.com (smtp100.rog.mail.re2.yahoo.com [206.190.36.78]) by mx1.freebsd.org (Postfix) with SMTP id 5A8C013C463 for ; Sun, 24 Dec 2006 22:24:48 +0000 (UTC) (envelope-from mike.jeays@rogers.com) Received: (qmail 6928 invoked from network); 24 Dec 2006 21:58:08 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=rogers.com; h=Received:X-YMail-OSG:Subject:From:To:Content-Type:Date:Message-Id:Mime-Version:X-Mailer; b=pDpwylkW7RuJa+mtHYoEshg7/hlKIToW8UuFT5PzLY+E4/6b4Ib1WixXGfxaPnu6pEEnFXfgJ//U2xXgNFhpZgQSkpNH5m86Z1F0673t4Xi94UFTLReuLdgtVUp+rGS5nIdmnUyo7VqDrtfzpsIlRNjt8B+8272ErJJb3o/PbH8= ; Received: from unknown (HELO ?192.168.2.100?) (mike.jeays@rogers.com@74.104.218.93 with plain) by smtp100.rog.mail.re2.yahoo.com with SMTP; 24 Dec 2006 21:58:07 -0000 X-YMail-OSG: Sb8hfXUVM1mYWdMBii.Mh8GSrEzxyoWFDvGYKTdmKz_xJaa16zMM0x3vWppX4KfsLdJaaW.PfrmmRsXgf_nBwdzd1yuk_6.AmQsmTpYwSMQZuuXjbnvfc4w.18PRiLL6FXBThM28Ugu3St2dVstOq0GL11soc0a.8SlI0RR9oTnPz1dYcG_vG3p3N54K From: Mike Jeays To: "freebsd-questions@FreeBSD. ORG" Content-Type: multipart/mixed; boundary="=-abvEPmJLSlnceJUm0X1O" Date: Sun, 24 Dec 2006 16:58:06 -0500 Message-Id: <1166997486.22414.36.camel@jansen> Mime-Version: 1.0 X-Mailer: Evolution 2.8.1 Cc: Subject: [Fwd: Re: Search & Replace Issue] X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 24 Dec 2006 22:24:49 -0000 --=-abvEPmJLSlnceJUm0X1O Content-Type: text/plain Content-Transfer-Encoding: 7bit --=-abvEPmJLSlnceJUm0X1O Content-Disposition: inline Content-Description: Forwarded message - Re: Search & Replace Issue Content-Type: message/rfc822 Subject: Re: Search & Replace Issue From: Mike Jeays To: Garrett Cooper In-Reply-To: <458EDF55.8050904@u.washington.edu> References: <458EDF55.8050904@u.washington.edu> Content-Type: text/plain Message-Id: <1166997440.22414.35.camel@jansen> Mime-Version: 1.0 X-Mailer: Evolution 2.8.1 Date: Sun, 24 Dec 2006 16:57:21 -0500 Content-Transfer-Encoding: 7bit On Sun, 2006-12-24 at 12:13 -0800, Garrett Cooper wrote: > Jack Stone wrote: > > > > > > > >> From: Parv > >> To: Josh Paetzel > >> CC: Jack Stone , freebsd-questions@freebsd.org > >> Subject: Re: Search & Replace Issue > >> Date: Sun, 24 Dec 2006 02:56:32 -0500 > >> > >> 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: > >> > > > >> > >
  • >> > > > >> > > >> > 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 > >> > > > > Parv and all: > > Many thanks for these various tips and your time to make them! > > > > I usually use sed(1) myself, but for the life of me, I could not find > > a way to properly apply delimiters or syntax to get it to work. I was > > close, but no cigar! Too many slashes and commas I guess. > > > > Such a "tool" will indeed be a giant timesaver! > > > > Merry Xmas! > > > > All the best, > > Jack > > One thing with regular expressions though, is that you can control > the command characters to use with defining the search and replace > keywords and replacements. If you see my example, I used pipes because > you had a number of forward slashes (/), so it allows you to cut down on > the number of escaping backslashes in your regular expression / replacement. > Cheers and a Merry Christmas to you too! > -Garrett > _______________________________________________ > freebsd-questions@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-questions > To unsubscribe, send any mail to "freebsd-questions-unsubscribe@freebsd.org" The -i option to sed enables it to rewrite a file in place, removing the need to create new files, delete the old ones, and rename the new ones. But it needs careful testing, and should never be used without a good backup of all the files that it might touch. Powerful tools are often dangerous! --=-abvEPmJLSlnceJUm0X1O--