Finding the same pattern in three consecutive lines in several files in a directory

view full story

http://www.unix.com – I know how to search for a pattern/regular expression in many files that I have in a directory. For example, by doing this: Code: grep -Ril "News/U.S." . I can find which files contain the pattern "News/U.S." in a directory. I am unable to accomplish about how to extend this code so that it can search for 3 consecutive lines in the files which contain the above pattern. The code should only output file names which contain three consecutive times the above pattern, and disregard less than 2 or 4 or greater. I mean: Code: News/U.S. News/U.S. News/U.S. As you can (HowTos)