Re: easy grep question
From: Barry Finkel (b19141_at_ACHILLES.CTD.ANL.GOV)
Date: 12/22/03
- Previous message: Raj Atwal: "Re: AIX apache with PHP"
- Maybe in reply to: Taylor, David: "easy grep question"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 22 Dec 2003 10:26:04 -0600 To: aix-l@Princeton.EDU
>I need to search a file for the string "ABC123" but only if the
>following line contains either "DEF456" or "GHI789". All three strings
>occur multiple times within this file, I am only concerned with the
>instances where the first string is immediately followed by one of the
>other two.
What do you want output? This UNTESTED awk script will output the lines
containing "ABC123" as per above.
# awk script
BEGIN{found=0;saved="";}
{
if (index($0,"ABC123">0)
{
saved = $0;
found = 1;
next;
}
if (((index($0,"DEF456")>0)||(index($0,"GHI789")>0))&&
(found==1))
{
print saved;
saved = "";
found = 0;
}
}
----------------------------------------------------------------------
Barry S. Finkel
Computing and Instrumentation Solutions Division
Argonne National Laboratory Phone: +1 (630) 252-7277
9700 South Cass Avenue Facsimile:+1 (630) 252-4601
Building 222, Room D209 Internet: BSFinkel@anl.gov
Argonne, IL 60439-4828 IBMMAIL: I1004994
- Previous message: Raj Atwal: "Re: AIX apache with PHP"
- Maybe in reply to: Taylor, David: "easy grep question"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]