Peter Hanke wrote
For a given file aaa.txt I want to check wether it contains a hex value
e.g. x'77' (=1 byte) BUT not a hex sequence x'8877' (=two bytes). In other
words byte value x'77' should exist but it must not NT be preceded by
byte value x'88'.
How can I specify this (pre-)conditions in NE regular expression
Read `perldoc perlre`
look for *negative lookbehind*:
Cperl -e "@x=qw(aa ab xb b); print qq($_\n) for grep /(?<!a)b/,@x"
xb
b
Perl likes hex too (documented in the same place):
Cperl -e "@x=qw(aa ab xb b);
print qq($_\n) for grep /(?<!\x61)\x62/,@x"
xb
b
and pass it e.g. to grep?
Presumably you mean perl's built in grep function rather than the
separate program of the same name.
Cperl -e "@x=qw(aa ab xb b);
$re='(?<!a)b';
print qq($_\n) for grep /$re/,@x"
xb
b
I haven't answered the first part of your question, I assume you already
know how to apply grep to a file and count the matches. Ditto
terminating the grep after the first match.