From owner-freebsd-questions@FreeBSD.ORG Tue Dec 30 21:09:03 2008 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id C8AB910656BA for ; Tue, 30 Dec 2008 21:09:03 +0000 (UTC) (envelope-from keramida@ceid.upatras.gr) Received: from igloo.linux.gr (igloo.linux.gr [62.1.205.36]) by mx1.freebsd.org (Postfix) with ESMTP id 253AD8FC14 for ; Tue, 30 Dec 2008 21:09:02 +0000 (UTC) (envelope-from keramida@ceid.upatras.gr) Received: from kobe.laptop (adsl119-205.kln.forthnet.gr [77.49.238.205]) (authenticated bits=128) by igloo.linux.gr (8.14.3/8.14.3/Debian-5) with ESMTP id mBUL765D008172 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT); Tue, 30 Dec 2008 23:07:13 +0200 Received: from kobe.laptop (kobe.laptop [127.0.0.1]) by kobe.laptop (8.14.3/8.14.3) with ESMTP id mBUL76Hj051412; Tue, 30 Dec 2008 23:07:06 +0200 (EET) (envelope-from keramida@ceid.upatras.gr) Received: (from keramida@localhost) by kobe.laptop (8.14.3/8.14.3/Submit) id mBUL755K051411; Tue, 30 Dec 2008 23:07:05 +0200 (EET) (envelope-from keramida@ceid.upatras.gr) From: Giorgos Keramidas To: Gary Kline References: <20081230193111.GA32641@thought.org> <20081230201623.GB65659@slackbox.xs4all.nl> <20081230205131.GA34211@thought.org> Date: Tue, 30 Dec 2008 23:07:05 +0200 In-Reply-To: <20081230205131.GA34211@thought.org> (Gary Kline's message of "Tue, 30 Dec 2008 12:51:31 -0800") Message-ID: <87abad4bk6.fsf@kobe.laptop> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (berkeley-unix) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-MailScanner-ID: mBUL765D008172 X-Hellug-MailScanner: Found to be clean X-Hellug-MailScanner-SpamCheck: not spam, SpamAssassin (not cached, score=-3.869, required 5, ALL_TRUSTED -1.80, AWL 0.53, BAYES_00 -2.60) X-Hellug-MailScanner-From: keramida@ceid.upatras.gr X-Spam-Status: No Cc: Roland Smith , FreeBSD Mailing List Subject: Re: well, blew it... sed or perl q again. 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: Tue, 30 Dec 2008 21:09:04 -0000 On Tue, 30 Dec 2008 12:51:31 -0800, Gary Kline wrote: > All right, then is this the right syntax. In other words, do > I need the double quotes to match the "http:" string? > > perl -pi.bak -e 'print unless "/m/http:/" || eof; close ARGV if eof' * Close, but not exactly right... You have to keep in mind that the argument to -e is a Perl expression, i.e. something you might type as part of a script that looks like this: #!/usr/bin/perl while () { YOUR-EXPRESSION-HERE; print $_; } One of the ways to print only the lines that do *not* match the "http://" pattern is: print unless (m/http:\/\//); Note how the '/' characters that are part of the m/.../ expression need extra backslashes to quote them. You can avoid this by using another character for the m/.../ expression delimiter, like: print unless (m!http://!); But you are not still done. The while loop above already contains a print statement _outside_ of your expression. So if you add this to a perl -p -e '...' invocation you are asking Perl to run this code: #!/usr/bin/perl while () { print unless (m!http://!); print $_; } Each line of input will be printed _anyway_, but you will be duplicating all the non-http lines. Use -n instead of -p to fix that: perl -n -e 'print unless (m!http://!)' A tiny detail that may be useful is that "http://" is not required to be lowercase in URIs. It may be worth adding the 'i' modifier after the second '!' of the URI matching expression: perl -n -e 'print unless (m!http://!i)' Once you have that sort-of-working, it may be worth investigating more elaborate URI matching regexps, because this will match far too much (including, for instance, all the non-URI lines of this email that contain the regexp example itself).