0

I am using grep with the -f option and I run into an issue when the pattern file given with -f is very long. The one that is failing for me has almost 300 thousand lines and 40 MBytes. grep does not refuse to run but ends Killed. Is there a specific maximum size for the pattern file?

4
  • If your patterns are strings (not regex) you could try to add -F switch. Otherwise, is something written to syslog (memory exhausted maybe)? Commented Nov 4, 2022 at 15:36
  • Both good tips, though -F does not help in my case. It could, however, fix some borderline cases. Syslog says Out of memory: Killed process 2965427 (grep) total-vm:1897916kB, anon-rss:1879488kB, file-rss:0kB, shmem-rss:0kB, UID:1000 pgtables:3736kB oom_score_adj:0 That would suggest that the limit will depend on memory, although 40 Megs of the original file does not seem that much. Commented Nov 4, 2022 at 15:41
  • I'd speculate that you're reaching some memory quota for the user you're running the command as. Could try running it with sudo (if you have sufficient privs) to see how they behaves. Don't really understand your use case from the description given, but 300k patterns seems a lot (and obviously causing you a problem). What if break it down into multiple files? You would have to process the input multiple times though. Commented Nov 4, 2022 at 16:46
  • sudo does not change the behaviour, grep gets killed just the same. I hit this issue by chance. I have a cron jobs that makes a list of new files that have appeared in a datastore, and then removes some based on a previously stored list. Normally it works, but I today I started the script with empty history, so the list of files to remove grew exceptionally big. I can avoid that condition, and I could certainly split the pattern file. Frankly I was just curious how large the chunks could be to be safe :-) Commented Nov 4, 2022 at 17:48

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.