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

Awk ERROR: Field $("....") is not correct 1

Status
Not open for further replies.

Tobsinte

Programmer
Jul 25, 2006
3
MY
Hi,

I'm trying to get the substr on a string and getting the below error.

|0060776818860803181712HMEHME0192HM01 A+0400UNKHMESMDEPART 1903 AM/PM 0000 |

awk: Field $(|0060776824460803181712HMEHME0192HM01 A+0400UNKHMESMUSNEXTDAY
0000 |)
is not correct.
The input line number is 1309. The file is kk.
The source line number is 3.

The code is:

awk '/\|00/ && /SM/ && /USNEXTDAY/ && (length($0) == 145) {CL=$0;
print CL;
status_code = substr($CL,51,2);
if (status_code != NULL && status_code == "SM")
{
remarks=substr($CL,53,44);
if (remarks != NULL && remarks ~ "USNEXTDAY")
{
awb=substr($CL,4,10);
dest=substr($CL,48,3);
printf ("Status code %2c\n",status_code);
printf ("Remarks %44c\n",remarks);
printf ("Airwaybill Number %10d\n",awb);
printf ("Destination %3c\n",dest);
}
}
next;
}' kk

Also, how will the awk react if the returned substring is NULL? Any idea?

Rgds,
 
You should refer to the variable as just CL, not $CL. $CL refers to the field numbered by the variable CL, i.e. if CL=3, then $CL would evaluate to the contents of field 3.

Annihilannic.
 
Thanks Annihilanic... I just cant believe what a stupid mistake I did. Before posting it in here, I spent quite a long time to figure out whats really wrong with the field but in vain. Once again thanks a lot. :)
 
It's an easy mistake to make (and overlook!) when you spend a lot of time writing perl and/or shell scripts where you always need the $s....

Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top