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
- X-seq: zsh-users 10652
- From: Chris Johnson <cjohnson@xxxxxxxxxx>
- To: zzapper <david@xxxxxxxxxx>
- Subject: Re: I want to list the NEXT line after a string appears in a list of files
- Date: Fri, 1 Sep 2006 11:28:56 -0400
- Cc: zsh-users@xxxxxxxxxx
- In-reply-to: <Xns9831A29573C98zzappergmailcom@xxxxxxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <Xns9831A29573C98zzappergmailcom@xxxxxxxxxxx>
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