[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: how to find lines containing two null characters?



-----BEGIN PGP SIGNED MESSAGE-----

On 9 Sep 1999, Mark Buda wrote:

> I want to do what
> 
> egrep '\000\000' files...
> 
> would do if egrep understood \NNN octal escape sequences. Is there
> something I'm missing in the egrep man page that would permit this? If
> not, is there some package among the bazillions of Debian packages
> that contains a program that will do this? (I've looked, but found no
> suspects.)

Behold, the power of Perl!

This one-liner should do it for you. You can either cat the file and pipe
it into this, or you can tack the filename on at the end.

  perl -ne '/\000\000/ and print;'

In this form it won't print the filename before each line if you specify
more than one file, the way grep will. That takes a slightly longer
one-liner:

  perl -ne '/\000\000/ and print "$ARGV:$_";'

Or, if you want the exact behavior of grep, only printing if more than one
file is specified:

  perl -e '$f=@ARGV; while(<>){ /\000\000/ and print $f>1?"$ARGV:$_":$_ }'


- -- 
  finger for PGP public key.



-----BEGIN PGP SIGNATURE-----
Version: 2.6.3ia
Charset: noconv

iQCVAwUBN9hUwL7M/9WKZLW5AQFDbwP9EH8tzlQ7UifOz3qnMaQFgyU8WmDZAfn+
3VgFmBsIEpAixbEc2h516P9R9T6ojVKp0ZOhD1uONCmfxg97EDwWeQlQHd6EQsqO
9d9iFUXiTh2pc4T3XU7jH4fhCJilcpWCSZdYMJLoiwUhfH+aelVcaczfHdh3Xllg
rz7WxadES2U=
=S48b
-----END PGP SIGNATURE-----


Reply to: