shell - show n lines after a grep search -
I am listing files for a pattern in the content of files, however, after trying to display 5 lines after searching . I'm running it on a MacOSX shell
I tried to do this
grep-A5 'pattern' *. *
Here I get the following output
file name line 1 file name line 2 file name line 3 file name line 4 file name line 5
I just want the lines to be output and the file name will not be my ideal output file name
line1 line2 line3 line4 line5
< / Pre>I also tried the following, but they did not work.
grep -l 'pattern' *. * | Head-5 Head-5 & Lt; Grep -l 'pattern' *. *
Any ideas on how to do this on the shell?
If you want to leave the file names from grep
in your output When you get multiple input files, you should use the -h
option (
Additionally, gives the option -A5
( If you have a grep GNU taste) you can use the - no-filename
instead.) Up to 5 lines of context around each match if you want the same as the good and the good Are but It seems that you want to limit grep
to 5 matches instead it will be -m5
for maximum 5 per file, or it will be head-5 < Pipe in / code> if you want only 5 overall.
Comments
Post a Comment