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 <david@xxxxxxxxxx>:
> 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

[snip]
zsh% cat test0.txt                                           
These             
are
lines,
I
do
not
care
about.
but
please
display this line.
zsh% cat test1.txt                                           
and please, oh please:
display this line, too.
not
this
one
zsh% function my_grep () {                                   
  local integer found=0
  while read line ; do
    (( found == 1 )) && print ${line} && return
    (( found == 0 )) && [[ ${line} = *${1}* ]] && found=1
  done < ${2}
}
zsh% for file in test*.txt ; do my_grep 'please' $file ; done
display this line.                                           
display this line, too.
[snap]

Regards, Frank



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