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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

deleting a line with awk based on column character positions

Status
Not open for further replies.

RJSHA1

Programmer
Apr 12, 2001
66
0
0
GB
Hi there,
I'm trying to write an AWK script where I have three variables that I pass to the script search a file for a line where the data in the columns matches what is passed in.

The data looks like this :-

aftn3200aftn3220CQA1-00000168.trigger
aftn3200aftn3220CQA1-00000169.trigger
aftn3200aftn3220CQA1-00000170.trigger
aftn3200aftn3220CQA1-00000176.trigger
aftn3200aftn3220CQA1-00000177.trigger
aftn3200aftn3220CQA1-00000178.trigger
aftn3200aftn3220CQA1-00000179.trigger

The fields that I'm trying to search on are
mnem 17-18
run_opt 19-20
batch_id 22-29

So if I passed in CQ A1 179 I would expect the resultant file to look like :-

aftn3200aftn3220CQA1-00000168.trigger
aftn3200aftn3220CQA1-00000169.trigger
aftn3200aftn3220CQA1-00000170.trigger
aftn3200aftn3220CQA1-00000176.trigger
aftn3200aftn3220CQA1-00000177.trigger
aftn3200aftn3220CQA1-00000178.trigger

Can anyone give me a few pointers as I'm struggling with the character column position bit of the script.


Thanks
Bob....
 
something like this should get you started:

nawk -v mnem=CQ -v run=A1 -v batch=179 -f rjsha.awk rjsha.txt

Code:
BEGIN {
  FLDmnem=17
  FLDmnemLen=2
  FLDrun=19
  FLDrunLen=2
  FLDbatch=22
  FLDbatchLen=8
}

{
  Lmnem=substr($0, FLDmnem, FLDmnemLen);
  Lrun=substr($0, FLDrun, FLDrunLen);
  Lbatch=int(substr($0, FLDbatch, FLDbatchLen));

#  printf("Lmnem->[%s] Lrun->[%s] Lbatch->[%s]\n", Lmnem, Lrun, Lbatch);

  if ( Lmnem == mnem && Lrun == run && Lbatch == batch)
     next;
  else
     print;
}

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Something like this ?
awk -v mnem=CQ -v run_opt=A1 -v batch_id=179 '
substr($0,17,2)==mnem && substr($0,19,2)==run_opt && substr($0,22,8)+0==batch_id
' /path/to/inputfile

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top