0

I'm trying to process multiple lines and extract a specific list of IPs from the text file with a large list of IPs (10000-ips.txt).

To extract specific IPs from the file, I would normally use:

egrep '111.11.111.11|222.22.222.22' 10000-ips.txt

But now I have to filter about 5000 IP and not only two 111.11.111.11|222.22.222.22 but egrep return “Argument list too long”

Example:

egrep '5000-IPs-to-find' 10000-ips.txt

Return:

/usr/bin/egrep: Argument list too long

I like to know, what is the best way to do this?

pancho
  • 176
  • 1
  • 2
  • 13
  • [Q: Argument list too long - Unix](https://stackoverflow.com/questions/6890632/argument-list-too-long-unix?r=SearchResults&s=1|183.9149) and more here [Error: “grep: Argument list too long” [duplicate]](https://stackoverflow.com/questions/29727135/error-grep-argument-list-too-long) and in the duplicate linked there. `xargs` or `find` are two solutions. – David C. Rankin Dec 04 '19 at 08:21
  • Loop over IPs and invoke `grep`? – stephanmg Dec 04 '19 at 08:23
  • Hi @stephanmg Yes I was thinking about this, but will be slow. – pancho Dec 04 '19 at 08:29
  • @pancho: Did you benchmark it? Is the file very large? – stephanmg Dec 04 '19 at 08:30
  • 2
    If there are no actual regular expressions in those patterns, just put them in a file one per line and use `grep -Ff 5000ips.txt 10000-ips.txt` – tripleee Dec 04 '19 at 08:30
  • @tripleee that did the trick. Thanks! – pancho Dec 04 '19 at 08:35

0 Answers0