Date: Mon, 22 Dec 2008 08:53:36 +0000 From: Matthew Seaman <m.seaman@infracaninophile.co.uk> To: Gary Kline <kline@thought.org> Cc: freebsd-questions@freebsd.org Subject: Re: Sed question Message-ID: <494F5590.3090400@infracaninophile.co.uk> In-Reply-To: <20081221222744.GA28185@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>
next in thread | previous in thread | raw e-mail | index | archive | help
This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enig9AEFF922DBF360348E8E97ED Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: quoted-printable 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: >=20 > 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 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. 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 --=20 Dr Matthew J Seaman MA, D.Phil. 7 Priory Courtyard Flat 3 PGP: http://www.infracaninophile.co.uk/pgpkey Ramsgate Kent, CT11 9PW --------------enig9AEFF922DBF360348E8E97ED Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.9 (FreeBSD) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iEYEAREIAAYFAklPVZcACgkQ8Mjk52CukIww7gCfb3eIYOJJPqIOpQlQw+sZRTsj o98AnAtxEP7HPpdpWiyXC1OiBw+8bPTh =GgrQ -----END PGP SIGNATURE----- --------------enig9AEFF922DBF360348E8E97ED--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?494F5590.3090400>