Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

pattern matching in AWK

Status
Not open for further replies.

IMAUser

Technical User
May 28, 2003
121
CH
Hi, I have a file like

BINDS #17:
bind 0: dty=2 mxl=22(22) mal=00 scl=00 pre=00 oacflg=00 oacfl2=1 size=352 offset=0
bfp=ffffffff7d05fa48 bln=22 avl=02 flg=05
value=18
bind 1: dty=2 mxl=22(22) mal=00 scl=00 pre=00 oacflg=00 oacfl2=1 size=0 offset=24
bfp=ffffffff7d05fa60 bln=22 avl=02 flg=01
value=6
bind 2: dty=2 mxl=22(22) mal=00 scl=00 pre=00 oacflg=00 oacfl2=1 size=0 offset=48
bfp=ffffffff7d05fa78 bln=22 avl=02 flg=01
value=2
BINDS #18:
bind 0: dty=2 mxl=22(22) mal=00 scl=00 pre=00 oacflg=00 oacfl2=1 size=352 offset=0
bfp=ffffffff7d05fa48 bln=22 avl=02 flg=05
value=18
BINDS #18:
bind 0: dty=2 mxl=22(22) mal=00 scl=00 pre=00 oacflg=00 oacfl2=1 size=352 offset=0
bfp=ffffffff7d05fa48 bln=22 avl=02 flg=05
value=18
bind 1: dty=2 mxl=22(22) mal=00 scl=00 pre=00 oacflg=00 oacfl2=1 size=0 offset=24
bfp=ffffffff7d05fa60 bln=22 avl=02 flg=01
value=20
bind 2: dty=2 mxl=22(22) mal=00 scl=00 pre=00 oacflg=00 oacfl2=1 size=0 offset=48
bfp=ffffffff7d05fa78 bln=22 avl=02 flg=01
value=30

What I need the awk program to do is
look for BINDS =18:
and then after that if the 3 line is "value=18" , 6th line is "value=20" and 9th line is value=20 print the lines between "BINDS #18:" till "value=30"

I started to write a program as below, its not completel written and even the logic is not proper, may need help on logic as well.

The program is not working at all, compliation errors and that is on line 2. Is there something wrong on the if statement.

BEGIN
if ($1 == "BINDS #18:") {
memo = 1
LineNo = 0
}
if (memo==1) {
LineNo = LineNo + 1
}
if ( LineNo == 3 )
{
if ( $1 == "value=18" )
Keep_line = 1
}
if ( LineNo == 6 )
{
if ( $1 == "value=20" )
Keep_line = 1
}
if ( LineNo == 9 )
{
if ( $1 == "value=30" )
Keep_line = 1
}
END

And if people have better ways to solve this please do let me know....

Many thanks...

 
I saved your data and named it binds so change your filename/path

open(FILE, "<binds");
@array = <FILE>;
close(FILE);

$stringToFind = "value=30";

for ($index = 0; $index <= $#array; $index++) {
last if $array[$index] =~ /$stringToFind/;
}

foreach (@array[$index-9..$index-0]) {
print("$index: $_");
$index++;
}


perl -e 'print $i=pack(c5,(40*2),sqrt(7600),(unpack(c,Q)-3+1+3+3-7),oct(104),10,oct(101));'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top