From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fee84,ba77b28a27fe5498 X-Google-Attributes: gidfee84,public From: Phil Farrell Subject: Re: Showing context and grep Date: 1997/09/30 Message-ID: <343144AA.7336@pangea.stanford.edu>#1/1 X-Deja-AN: 276817920 References: <342BB790.AB3@US.GASES.BOC.COM> To: "KATHY.WEST@US.GASES.BOC.COM" Organization: Stanford University School of Earth Sciences Newsgroups: comp.unix.osf.osf1 KATHY.WEST@US.GASES.BOC.COM wrote: > > Hi all, > > I am using grep to search many large log files for different events. > For each line that's matched, I would like to show the matched line and > the line that immediately follows it. You could to this with a small awk program. For example, if you are looking for the regular expression "regexp", and want to see the following line as well, this awk program would do the job: awk '/regexp/ {print;c=1;next}; c == 1 {print;c=0}' inputfiles This could be extended to print additional lines of following context by incrementing the variable "c" and then testing against some limit before resetting to 0. -- Phil Farrell, Computer Systems Manager Stanford University School of Earth Sciences farrell@pangea.stanford.edu