“grep: line too long” error message

2020-07-08 06:02发布

问题:

I used the following syntax in order to find IP address under /etc

(answered by Dennis Williamson in superuser site)

but I get the message "grep: line too long".

Someone have idea how to ignore this message and why I get this?

  grep -Er '\<([0-9]{1,3}\.){3}[0-9]{1,3}\>' /etc/
  grep: line too long

回答1:

The find/xargs solution didn't work for me, but resulted in the same error.

I solved this problem by using the -I grep option (ignore binary files). In my case there must have been a binary file in the list of files to search that had no linebreaks, so grep tries to read in a gigantic line that is too big. That's my guess at what this error means.

I got the idea from: http://web.archiveorange.com/archive/v/am8x7wI0r0243prrmYd4

This might not work for you of course if there's a text file with a line that is too long.



回答2:

Use find to build a list of files to grep,

find /etc -type f -print0 | xargs -r0 grep -E '\<([0-9]{1,3}\.){3}[0-9]{1,3}\>'

In general find is a more flexible way of traversing the filesystem and building lists of files for other programs.



回答3:

Perhaps your grep has a bug and scans by accident a binary file with too long lines (i.e. too much characters for grep to handle between two newlines). See this red hat page for more details (bug page).



标签: grep