• Advertisement
Sign in to follow this  

Urgent help with awk programming....

This topic is 4221 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I encounter some error while trying to run an awk program as below : awk '{a=substr($0, 52,4) if (a ~ /MS/ || a ~/MG/ || a ~/SS/ || a ~ /SM/ || a ~ /AJ/ || a ~/HY/ || a ~/HL/ || a ~ /CC/ || a ~ /AP/ || a ~/NL/ || a ~/MP/ || a ~ /VT/ || a ~ /NC/ || a ~/NU/ || a ~/OR/ || a ~ /PO/ || a ~ /ND/ || a ~/SD/ || a ~/EU/ || a ~ /LT/ || a ~ /HU/ || a ~/NY/ || a ~/TS/ || a ~ /SO/ || a ~ /HJ/ || a ~/DO/ || a ~/PI/ || a ~ /PL/ || a ~ /AT/ || a ~/AV/ || a ~/MB/ || a ~ /MW/ || a ~ /MO/ || a ~/ML/ || a ~/MH/ || a ~ /MN/ ) print}' $src_file > $tmp_file It will give me an error such as invalid syntax at line 3.4.5 etc... In addition,I will get an error bailing out message near the last line...which is print}' $src_file > $tmp_file Can someone please help and advise? This is quite urgent. Thanks.

Share this post


Link to post
Share on other sites
Advertisement
It works fine here:

bytecoder@fireball:~ $ cat > test
ASD;FKJSD;FLKJSD;FKSJDF;LJS;FKNSKDFS
FAJSDLFJS;DKFLJSDFL;KJSDF;LKJSDF;LKSJDF
SDF
SDFSDFLKJSDLFKSJDFL
bytecoder@fireball:~ $ awk '{a=substr($0, 52,4)
if (a ~ /MS/ || a ~/MG/ || a ~/SS/ || a ~ /SM/ ||
a ~ /AJ/ || a ~/HY/ || a ~/HL/ || a ~ /CC/ ||
a ~ /AP/ || a ~/NL/ || a ~/MP/ || a ~ /VT/ ||
a ~ /NC/ || a ~/NU/ || a ~/OR/ || a ~ /PO/ ||
a ~ /ND/ || a ~/SD/ || a ~/EU/ || a ~ /LT/ ||
a ~ /HU/ || a ~/NY/ || a ~/TS/ || a ~ /SO/ ||
a ~ /HJ/ || a ~/DO/ || a ~/PI/ || a ~ /PL/ ||
a ~ /AT/ || a ~/AV/ || a ~/MB/ || a ~ /MW/ ||
a ~ /MO/ || a ~/ML/ || a ~/MH/ || a ~ /MN/ )
print}' test
bytecoder@fireball:~ $ echo $?
0

I can't tell if it does what it's supposed to, but it doesn't give me any errors (the output is empty).

Share this post


Link to post
Share on other sites
Quote:
Original post by cucubird
It will give me an error such as invalid syntax at line 3.4.5 etc...

In addition,I will get an error bailing out message near the last line...which is print}' $src_file > $tmp_file


I get no error just cutting and pasting your awk script. It appears, however, that you are running it from within a shell script, and I believe your errors are coming from the shell, not from awk. Perhaps using on e of the shell-scripting debugging techniques (eg. set -x) will produce more clues.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement