“grep: line too long” error message

2020-07-08 05:52发布

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

标签: grep
3条回答
霸刀☆藐视天下
2楼-- · 2020-07-08 06:46

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楼-- · 2020-07-08 06:48

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).

查看更多
等我变得足够好
4楼-- · 2020-07-08 06:49

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.

查看更多
登录 后发表回答