Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Newbie grep question

0 views
Skip to first unread message

Nachman Yaakov Ziskind

unread,
Jun 12, 2000, 3:00:00 AM6/12/00
to Scolist
... any easy way to sed/awk/grep out the line AFTER the marker line?
I.e., I have text like this:

junk
junk
MARK
I want this line
junk
junk
junk
MARK
I want this line
junk
junk
MARK
I want this line
junk
junk
junk
junk
MARK
I want this line
MARK
I want this line

and so forth? No particular patterns/line counts to rely on - just the
presence of "MARK" lets me know that the next line is valuable. I spent some
time reading man pages, and managed to hit
MEGO. :-(

SCO OSE 505

Thanks!


--
_________________________________________
Nachman Yaakov Ziskind, EA, CNE aw...@egps.com
Attorney and Counselor-at-Law http://yankel.com
Economic Group Pension Services http://egps.com
Actuaries and Employee Benefit Consultants

Darryl Krasman

unread,
Jun 12, 2000, 3:00:00 AM6/12/00
to

Assuming your data is in a file called "data" try this:
$ awk '/^MARK/ { OK = 1; continue } OK == 1 { print $0; OK = 0 }' data
--
Darryl
Ideal Computer Group Inc.

Night Wolf

unread,
Jun 13, 2000, 3:00:00 AM6/13/00
to
ok I imagine there is an easier way to do this with grep/sed (but hey isn't that the beauty of unix... there's more than one way to do anything)

here's a quick and dirty awk script that worked on your example text (and I even though in some comments to help you out).

#!/usr/bin/awk

begin {
#
# pnext is basicly a boolean that
# tells awk to print the next line if it's set
#

#
#set it to 0 (false) initially
#
pnext = 0;
}

#
# main procedure...
#

{

#
# if pnext is set print this line
# and reset pnext
#
if (pnext == 1) {
print $0;
pnext = 0;
}
}

#
# match /MARK/ and set pnext if it's found
# this has to be after the main proc to get it
# to pick up the next line in the stream.
#

/MARK/ {
pnext = 1;
}


dave

0 new messages