I’m using grep to extract lines across a set of files:
grep somestring *.log
Is it possible to limit the maximum number of matches per file to the last n matches from each file?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Well I think grep does not support to limit N matches from the end of file so this is what you have to do
Replace
tail -1-1 with N. (-H options is to print the file name else it wont be printed if you are grep in a single file and thats exactly we are doing above)NOTE: Above soln will work fine with file names with spaces.
For N matches from the start of the file
Replace
-m11 with N.