Too long error when trying to grep log files
When I type this at a shell prompt:
grep -r "ambiguously" .
I am getting the error:
grep: line too long.
Basically the current directory is the logs directory and I am trying to find the sql error "Column is ambiguous" in all the log files.
But why am I getting the error? The files are very large, is this the main reason?
You must try
find -type f -exec grep PATTERN {} +
The command line limitation can be found on linux with
$ getconf ARG_MAX
Incl. * BSD with
$ sysctl kern.argmax
See http://www.cyberciti.biz/faq/argument-list-too-long-error-solution/ for details .
"grep: line too long" does not necessarily mean that the file or files where the line is "too long" contains the line you are looking for.
You might want to try:
for i'm in find /var/log -type f
; do echo $ i && & grep PATTERN $ i; done | tee / tmp / output.txt
or
for i'm in find /var/log -type f
; do echo $ i && & grep PATTERN $ i; done
depending on how many files you are viewing.
"Line too long" will appear in the standard error and you will see it on screen if you can scroll back. It could be "lastlog".
you get the error because grep is limited by the number of files it can receive on the command line.
try it
ls -b . | xargs grep "ambiguously"
Edit: This solution only works if you don't need to recursively