

When this option is used, grep prints the matches to standard output prefixed with the line number. I imagine somewhere in the log file are some control characters that are tricking grep, but the beginning and end of the file looks like normal text. The -n ( or line-number ) option tells grep to show the line number of the lines containing a string that matches a pattern. Using yet another useful pattern search command grep, you can get the total number of lines in a file. Count Number Of Lines Using Grep Command.

So, combining it with the -n option, it counts the total number of lines in a file passed as an argument. The issue I'm facing is that grep finds the line but does not give it to me, instead printing message about it being a binary file: > grep -n 6307459 /disk2/user/test/logs/-23-42-52-7224.logīinary file /disk2/user/test/logs/-23-42-52-7224.log matches Here, '' prints the current line number to standard output. I'm using grep to find the line number of the occurrence and then using head and tail to get the section I'm interested in reviewing. It is huge and I need to find around a million lines starting from the occurrence of a string 6307459 in the log file and view it in emacs. I'm on Centos 5 Linux and using GNU grep v2.5.1 and looking at a 36GB log file.
