How Do You Fix the Error “grep: memory exhausted”?

Problem scenario
You run a grep command but it fails. You get a message about "memory exhausted." What should you do?

Possible Solution #1
If you are comparing two files line-by-line, try reversing the order of the file arguments for the grep command. For example try these two versions:

grep -f a.txt b.txt
grep -f b.txt a.txt

If the file in the left argument is smaller, we know it uses less memory.

Possible Solution #2
If you have enough disk space, add swap space. See this posting if you need more assistance.

Possible Solution #3
See How Do You Add Memory to a Server? for resizing the VM to add more memory.

Leave a comment

Your email address will not be published. Required fields are marked *