From owner-freebsd-questions@FreeBSD.ORG Tue Dec 23 19:09:00 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 57E98106567E for ; Tue, 23 Dec 2008 19:09:00 +0000 (UTC) (envelope-from kline@thought.org) Received: from aristotle.thought.org (ns1.thought.org [209.180.213.210]) by mx1.freebsd.org (Postfix) with ESMTP id EA0BD8FC1F for ; Tue, 23 Dec 2008 19:08:54 +0000 (UTC) (envelope-from kline@thought.org) Received: from thought.org (tao.thought.org [10.47.0.250]) (authenticated bits=0) by aristotle.thought.org (8.14.2/8.14.2) with ESMTP id mBNJ9NRe035755; Tue, 23 Dec 2008 11:09:23 -0800 (PST) (envelope-from kline@thought.org) Received: by thought.org (nbSMTP-1.00) for uid 1002 kline@thought.org; Tue, 23 Dec 2008 11:08:49 -0800 (PST) Date: Tue, 23 Dec 2008 11:08:49 -0800 From: Gary Kline To: Matthew Seaman Message-ID: <20081223190849.GD98784@thought.org> References: <20081221053407.GA87868@thought.org> <877i5unkx4.fsf@kobe.laptop> <1229854084.6392.52.camel@ethos> <20081221140658.GA24691@marge.bs.l> <20081221222744.GA28185@thought.org> <494F5590.3090400@infracaninophile.co.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <494F5590.3090400@infracaninophile.co.uk> User-Agent: Mutt/1.4.2.3i X-Organization: Thought Unlimited. Public service Unix since 1986. X-Of_Interest: With 22 years of service to the Unix community. X-Spam-Status: No, score=-4.4 required=3.6 tests=ALL_TRUSTED,BAYES_00 autolearn=ham version=3.2.3 X-Spam-Checker-Version: SpamAssassin 3.2.3 (2007-08-08) on aristotle.thought.org Cc: freebsd-questions@freebsd.org Subject: Re: Sed question 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, 23 Dec 2008 19:09:00 -0000 On Mon, Dec 22, 2008 at 08:53:36AM +0000, Matthew Seaman wrote: > Gary Kline wrote: > > > anyway, this is one for giiorgos, or another perl wiz. i've > > been using the perl subsitution cmd one-liner for years with > > unfailing success. is there a way of deleting lines with perl > > using the same idea as: > > > > perl -pi.bak -e 's/OLDSTRING/NEWSTRING/g' file1 file2 fileN > > To delete lines matching a R.E. (grep -v effectively): > > perl -ni.bak -e 'm/SOMETHING/ || print;' file1 file2 fileN > Matthew, I've been trying, unsuccessfully, to parse the above. What does the "m" [in 'm/SOMETHING/' do. i thought it was 'match' ... and another one, just FWIW: can perl's regex be set to ignore cases? > To delete lines by number from many files -- eg. exclude lines 3 to 7: > > perl -ni.bak -e 'print unless ( 3 .. 7 ); close ARGV if eof;' \ > file1 file2 fileN > > The malarkey with 'close ARGV' is necessary because otherwise perl > won't reset the input line number counter ($.) for each new file. yeah, it's pretty important to reset the counter to zero since i've got so many files. one way to avoid that extended line would be to embed the perl string within a /bin/shell script, :-) Scripts within scripts, eh? lol. Oh: a final question. does the perl regex match vi's /\ ? it seemed like this plot in /OLDSTRING/ failed last sunday. i'm not entirely sure, tho. thanks much, gary > The range expression ( N .. M ) can take matching terms rather than > line numbers, so you can also do things like: > > perl -ni.bak -e 'print unless ( m/FIRST/ .. m/SECOND/ )' \ > file1 file2 fileN > > Cheers, > > Matthew > > -- > Dr Matthew J Seaman MA, D.Phil. 7 Priory Courtyard > Flat 3 > PGP: http://www.infracaninophile.co.uk/pgpkey Ramsgate > Kent, CT11 9PW > -- Gary Kline kline@thought.org http://www.thought.org Public Service Unix http://jottings.thought.org http://transfinite.thought.org The 2.17a release of Jottings: http://jottings.thought.org/index.php