I read your solution above using awk, and I wander if you could adapt it to my need, which differs as following:
- need to process all files with filenames like "filename*" in the current directory
- need to extract line containing pattern, plus following 5 lines
in grep terms: grep "pattern containing spaces" filename*
but my grep does not apprear to have options for extracting the context of the matching line.
The background to this is:
I need to produce a list of programs (files) that are able to modify a given table(indicated by the search pattern). The particular language defines access to table on several subsequent lines of code. I would need grep to search on "pattern", and extract the record containg the pattern, followed by say the next 5 records.
then I can visually scan the output and determine which programs will modify the table, given that words like 'write', 'rewrite' 'delete' etc will be present.
PHV,
Thanks for the quick answer, seems to be doing something, the only problem is that I cannot interprete the output: I would need the file names to also be displayed, either preceeding, or on the same line, for each chunk of lines being extracted; at the moment I cannot determine from the output which lines belong under which file. Is there a solution to the issue?
grep -B 3 'test' inputfile
grep -A 5 'pattern with spaces' filename*
----------------------------------------------------------------------------
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.