I have got the printf() error in AWK (AIX Unix). It seems that I will never get that AWK work with my user-defined shell variables.
Please help!!!
I was trying to print some fileds from input.dat into an output file. The other fields of the output file are from Unix shell variables.
### input.dat
ZYRTEC 5 MG TABLET |ZYRTEC 5 MG TABLET F|F0307|
ZYRTEC-D TABLET |ZYRTEC-D TABLET F|F0308|
ACEON 4 MG TABLET |ACEON 4 MG TABLET P|P0001|
### Output
F0307|EN|ZYRTEC 5 MG TABLET F|dbl|04/24/2006 04:54:04 PM|
F0308|EN|ZYRTEC-D TABLET F|dbl|04/24/2006 04:54:04 PM|
P0001|EN|ACEON 4 MG TABLET P|dbl|04/24/2006 04:54:04 PM|
Here is the scipt I used, which generated the AWK parseing error as following.
#!/bin/ksh
user=`whoami`
tmstamp=`date +"%m/%d/%G %r"`
echo "user: <$user>"
echo "tmstamp: <$tmstamp>"
#awk -F'|' '{printf "%s|%2s|%s|\n", $3, "EN", $2}' input.dat
awk -F'|' '{printf "%s|%2s|%s|%-16s|%-24s|\n", $3, "EN", $2, '$user', '$tmstamp'}' input.dat
/home/users/dbl/PPM/database> gen_code.awk
user: <dbl>
tmstamp: <04/24/2006 04:58:16 PM>
Syntax Error The source line is 1.
The error context is
{printf "%s|%2s|%s|%-16s|%-24s|\n", $3, "EN", $2, dbl, >>> 04/24/2006 <<<
awk: 0602-502 The statement cannot be correctly parsed. The source line is 1.
Please help!!!
I was trying to print some fileds from input.dat into an output file. The other fields of the output file are from Unix shell variables.
### input.dat
ZYRTEC 5 MG TABLET |ZYRTEC 5 MG TABLET F|F0307|
ZYRTEC-D TABLET |ZYRTEC-D TABLET F|F0308|
ACEON 4 MG TABLET |ACEON 4 MG TABLET P|P0001|
### Output
F0307|EN|ZYRTEC 5 MG TABLET F|dbl|04/24/2006 04:54:04 PM|
F0308|EN|ZYRTEC-D TABLET F|dbl|04/24/2006 04:54:04 PM|
P0001|EN|ACEON 4 MG TABLET P|dbl|04/24/2006 04:54:04 PM|
Here is the scipt I used, which generated the AWK parseing error as following.
#!/bin/ksh
user=`whoami`
tmstamp=`date +"%m/%d/%G %r"`
echo "user: <$user>"
echo "tmstamp: <$tmstamp>"
#awk -F'|' '{printf "%s|%2s|%s|\n", $3, "EN", $2}' input.dat
awk -F'|' '{printf "%s|%2s|%s|%-16s|%-24s|\n", $3, "EN", $2, '$user', '$tmstamp'}' input.dat
/home/users/dbl/PPM/database> gen_code.awk
user: <dbl>
tmstamp: <04/24/2006 04:58:16 PM>
Syntax Error The source line is 1.
The error context is
{printf "%s|%2s|%s|%-16s|%-24s|\n", $3, "EN", $2, dbl, >>> 04/24/2006 <<<
awk: 0602-502 The statement cannot be correctly parsed. The source line is 1.