0

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?

scdmb
  • 123
  • 3
    Note that "\\x55" is '\x55' while if your shell is bash in its default configuration, echo "\\\\x55" outputs \\x55. Some other echo 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:50
  • @StéphaneChazelas The same happens when single quotes are used. – scdmb Sep 20 '15 at 20:00
  • Do you mean that grep -aboP '\x55' bigfile is OK, but printf '%s\n' '\x55' | grep -aboPf - bigfile returns with memory exhausted? – Stéphane Chazelas Sep 20 '15 at 20:04
  • This echo '\\\\x55' | grep -aboPf - bigfile causes memory exhausted problem but for some reason this echo '\x55' | grep -aboPf - bigfile works as expected. – scdmb Sep 20 '15 at 20:09

1 Answers1

0

All right, using single quotes and removing some backslashes seems to work:

$ echo '\x55' | grep -aboPf - bigfile
510:U
1049086:U
1049598:U

Thanks @StéphaneChazelas for the hint.

scdmb
  • 123