From: Barry Finkel (b19141@ACHILLES.CTD.ANL.GOV)
Date: Mon Dec 22 2003 - 11:26:04 EST
>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
This archive was generated by hypermail 2.1.7 : Wed Apr 09 2008 - 22:17:25 EDT