Hi,
I want to return all the record numbers, between TABLENAME and END pairs, if it finds a match for X in field2 of that record.
The layout is as follows:
:TABLENAME
:RECORD 1
; Field2 Field3 Field 4
01, X, 99, 4321
02, X, 99, 4322
03, X, 99, 4323
04, X, 99, 4324
05, X, 99, 4325
06, X, 99, 4326
07, X, 99, 4327
08, X, 99, 4328
09, X, 99, 4329
10, X, 99, 4330
11, X, 99, 4331
12, X, 99, 4332
13, X, 99, 4333
14, X, 99, 4334
15, X, 99, 4335
16, X, 99, 4336
17, X, 99, 4337
18, X, 99, 4338
19, X, 99, 4339
20, X, 99, 4340
21, X, 99, 4341
22, X, 99, 4342
23, X, 99, 4343
24, X, 99, 4344
:RECORD 2
:END
On the output I should get a list of record numbers:
Record 1,2,3,8,10, 30 etc
Here is what I have been playing with:
nawk -v X=$1 '
BEGIN {
RS == ":";
FS = "";
VAR="VAR"
}
/:TABLENAME/,/:END/ { if ( ":RECORD" == $1) { VAR = $2; next
{ FS = ",";
if ( X == $2) { printf ("%s\n", VAR)
}
}
}
}'
Thanks.
I want to return all the record numbers, between TABLENAME and END pairs, if it finds a match for X in field2 of that record.
The layout is as follows:
:TABLENAME
:RECORD 1
; Field2 Field3 Field 4
01, X, 99, 4321
02, X, 99, 4322
03, X, 99, 4323
04, X, 99, 4324
05, X, 99, 4325
06, X, 99, 4326
07, X, 99, 4327
08, X, 99, 4328
09, X, 99, 4329
10, X, 99, 4330
11, X, 99, 4331
12, X, 99, 4332
13, X, 99, 4333
14, X, 99, 4334
15, X, 99, 4335
16, X, 99, 4336
17, X, 99, 4337
18, X, 99, 4338
19, X, 99, 4339
20, X, 99, 4340
21, X, 99, 4341
22, X, 99, 4342
23, X, 99, 4343
24, X, 99, 4344
:RECORD 2
:END
On the output I should get a list of record numbers:
Record 1,2,3,8,10, 30 etc
Here is what I have been playing with:
nawk -v X=$1 '
BEGIN {
RS == ":";
FS = "";
VAR="VAR"
}
/:TABLENAME/,/:END/ { if ( ":RECORD" == $1) { VAR = $2; next
{ FS = ",";
if ( X == $2) { printf ("%s\n", VAR)
}
}
}
}'
Thanks.