From owner-freebsd-questions@FreeBSD.ORG Sun Dec 24 20:13:10 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 4B4F616A403 for ; Sun, 24 Dec 2006 20:13:10 +0000 (UTC) (envelope-from youshi10@u.washington.edu) Received: from mxout2.cac.washington.edu (mxout2.cac.washington.edu [140.142.33.4]) by mx1.freebsd.org (Postfix) with ESMTP id 2A2C913C466 for ; Sun, 24 Dec 2006 20:13:10 +0000 (UTC) (envelope-from youshi10@u.washington.edu) Received: from smtp.washington.edu (smtp.washington.edu [140.142.32.141] (may be forged)) by mxout2.cac.washington.edu (8.13.7+UW06.06/8.13.7+UW06.09) with ESMTP id kBOKD994025743 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Sun, 24 Dec 2006 12:13:09 -0800 X-Auth-Received: from [128.208.5.99] (nilakantha.cs.washington.edu [128.208.5.99]) (authenticated authid=youshi10) by smtp.washington.edu (8.13.7+UW06.06/8.13.7+UW06.09) with ESMTP id kBOKD9GU004827 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT) for ; Sun, 24 Dec 2006 12:13:09 -0800 Message-ID: <458EDF55.8050904@u.washington.edu> Date: Sun, 24 Dec 2006 12:13:09 -0800 From: Garrett Cooper User-Agent: Thunderbird 1.5.0.9 (Windows/20061207) MIME-Version: 1.0 To: freebsd-questions@freebsd.org References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-PMX-Version: 5.2.2.285561, Antispam-Engine: 2.5.0.283055, Antispam-Data: 2006.12.24.115433 X-Uwash-Spam: Gauge=IIIIIII, Probability=7%, Report='__CP_URI_IN_BODY 0, __CT 0, __CTE 0, __CT_TEXT_PLAIN 0, __HAS_MSGID 0, __MIME_TEXT_ONLY 0, __MIME_VERSION 0, __SANE_MSGID 0, __USER_AGENT 0' Subject: 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 20:13:10 -0000 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