Hi,
I have a shell script that uses awk and I build the awk command from variables. I'm having a problem because some of the data contains the " character and is messing up my quoting. Can someone help me and tell me how to resolve the quoting issue or a better way to do this. Here's my script and a sample of output. BAsically I have two files ... FILEA contains some fields that I supplie to the awk command to find matches in FILEB. Some of my 'prod' variable data contains the '"' character.
Script:
#!/bin/sh
while read line
do
ven=`echo $line | cut -c 122-124`
prod=`echo $line | cut -c 32-39`
clr=`echo $line | cut -c 21-30`
q=`echo $line | cut -c 54-62`
awk -e 'BEGIN { FS = "," }
$16 == "'$ven'" && $5 == "'$prod'" && $4 == "'$clr'" {
if ( "'$q'" != $7 ) { print $16,$5,$4,$7,"'$q'" }
}
' <FILEA
done <FILEB
---- ERROR OUTPUT -----
Note that the $5 == $prod where $prod is 60"GRGTE. The " messes up my quoting.
awk: newline in string { $4 == ...
at line 2 of program << BEGIN { FS = "," }
... >>
context is
$16 == "ZEL" && $5 == "60"GRGTE" && $4 == "WHITE " { >>>
<<<
awk: Syntax error
at line 3 of program << BEGIN { FS = "," }
... >>
1 extra }
awk: bailing out
at line 3 of program << BEGIN { FS = "," }
... >>
-----------------
Thanks for any help. Maybe there's a better way to do this, if so I'll take any suggestions.
LEE
I have a shell script that uses awk and I build the awk command from variables. I'm having a problem because some of the data contains the " character and is messing up my quoting. Can someone help me and tell me how to resolve the quoting issue or a better way to do this. Here's my script and a sample of output. BAsically I have two files ... FILEA contains some fields that I supplie to the awk command to find matches in FILEB. Some of my 'prod' variable data contains the '"' character.
Script:
#!/bin/sh
while read line
do
ven=`echo $line | cut -c 122-124`
prod=`echo $line | cut -c 32-39`
clr=`echo $line | cut -c 21-30`
q=`echo $line | cut -c 54-62`
awk -e 'BEGIN { FS = "," }
$16 == "'$ven'" && $5 == "'$prod'" && $4 == "'$clr'" {
if ( "'$q'" != $7 ) { print $16,$5,$4,$7,"'$q'" }
}
' <FILEA
done <FILEB
---- ERROR OUTPUT -----
Note that the $5 == $prod where $prod is 60"GRGTE. The " messes up my quoting.
awk: newline in string { $4 == ...
at line 2 of program << BEGIN { FS = "," }
... >>
context is
$16 == "ZEL" && $5 == "60"GRGTE" && $4 == "WHITE " { >>>
<<<
awk: Syntax error
at line 3 of program << BEGIN { FS = "," }
... >>
1 extra }
awk: bailing out
at line 3 of program << BEGIN { FS = "," }
... >>
-----------------
Thanks for any help. Maybe there's a better way to do this, if so I'll take any suggestions.
LEE