When I try to find a specific byte with grep
not using pipe I get some output:
$ grep -aboP "\\x55" bigfile
510:U
1049086:U
1049598:U
But when a pattern is supplied via pipe then there is a memory exhausted error:
$ echo "\\\\x55" | grep -aboPf - bigfile
grep: memory exhausted
Why does it happen and how to make it work?
"\\x55"
is'\x55'
while if your shell is bash in its default configuration,echo "\\\\x55"
outputs\\x55
. Some otherecho
implementations would output\x55
. It's not a good idea to use echo or double quotes when backslashes are involved. – Stéphane Chazelas Sep 20 '15 at 19:50grep -aboP '\x55' bigfile
is OK, butprintf '%s\n' '\x55' | grep -aboPf - bigfile
returns withmemory exhausted
? – Stéphane Chazelas Sep 20 '15 at 20:04echo '\\\\x55' | grep -aboPf - bigfile
causes memory exhausted problem but for some reason thisecho '\x55' | grep -aboPf - bigfile
works as expected. – scdmb Sep 20 '15 at 20:09