Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"grep: line too long" error message

Tags:

grep

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
like image 670
lidia Avatar asked Sep 07 '10 09:09

lidia


2 Answers

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.

like image 162
Shorin Avatar answered Sep 24 '22 11:09

Shorin


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.

like image 26
jmtd Avatar answered Sep 24 '22 11:09

jmtd