Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: I want to list the NEXT line after a string appears in a list of files



zzapper sent me the following 0.3K:

> I want to list the NEXT line after a string appears in a list of files
> 
> eg 
> > egrep "Anecdote" m??.txt (But display next line)
> 
> I guess Sed/Awk would do this, I would probably use Perl.
> 
> Suggestions pls

cat file | awk 'BEGIN {print_next = 0;} {if (print_next) {print $0;
   print_next = 0;}} /PATTERN/ {print_next = 1;}'

Here's an awk solution.  If your line matches PATTERN, it sets a flag.
When the next record is read, the flag is evaluated.  If set, the record
is printed.

This solution allows for a single line to both be printed and match.

-- 
Chris Johnson
cjohnson@xxxxxxxxxx
http://www.cs.utk.edu/~cjohnson



Messages sorted by: Reverse Date, Date, Thread, Author