From: Marc Chantreux <marc.chantreux@ulpmm.u-strasbg.fr>
To: zsh-users@sunsite.dk
Subject: Re: I want to list the NEXT line after a string appears in a list of files
Date: Fri, 1 Sep 2006 18:52:36 +0200 [thread overview]
Message-ID: <20060901165235.GA2122@ulpmm.u-strasbg.fr> (raw)
In-Reply-To: <Xns9831A29573C98zzappergmailcom@80.91.229.5>
le 01/09/2006,
zzapper nous écrivait :
> Hi
> I want to list the NEXT line after a string appears in a list of files
choose your destiny :
- little files : zsh
- medium : sed/awk (1)
- big : perl
(1) every one but the GNU one which is damn slow !
echo '
find a
find a
find a
find a
pattern
x
and print it
' > file
print sed:
sed -n '/pattern/ { # if pattern found
n # read next line
p # print the current line
}' < file
print wich can be written as:
sed -n '/pattern/{n;p}' < file
print perl:
perl -lne 'print $_=<> if /pattern/' file
print awk:
awk '/pattern/ { getline ; print }' file
print zsh -----------------
print first occurence :
# 1. store the content of file, line by line
content=( ${(f)"$( < file)"} )
# find a line containing your pattern
# > ${content[(i)*pattern*]}
# and print the next one
print ${content[${content[(i)*pattern*]} + 1]}
print all occurences :
while {read} {
[[ $REPLY == *pattern* ]] &&
read line &&
print $line
} < file
regards
--
téléphone : 03.90.24.00.19
courriel : marc.chantreux@ulpmm.u-strasbg.fr
---------------------------------------
prev parent reply other threads:[~2006-09-01 16:52 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-09-01 14:59 zzapper
2006-09-01 15:15 ` John Eikenberry
2006-09-02 13:59 ` zzapper
2006-09-01 15:15 ` Frank Terbeck
2006-09-02 18:41 ` zzapper
2006-09-01 15:27 ` Roman Cheplyaka
2006-09-01 15:36 ` zzapper
2006-09-01 15:28 ` Chris Johnson
2006-09-01 16:52 ` Marc Chantreux [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20060901165235.GA2122@ulpmm.u-strasbg.fr \
--to=marc.chantreux@ulpmm.u-strasbg.fr \
--cc=zsh-users@sunsite.dk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).