AWk - supress warning

Hi,

I am trying to run a script using awk and sed a few times.

The script itself seems to work fine but in a final awk statement it throws up a warning:

awk: warning: escape sequence `\.' treated as plain `.'

script:

CMD="BEGIN{OFS=FS=\"|\"}{if(\$1==\"$SYMBOL_CODE\"){\$4=$NEW_PREV_CLOSE}}{print \$0}"

awk "$CMD" PreviousClose2.asp | grep -w $SYMBOL_CODE >> EUTssPrevClose.txt

$SYMBOL_CODE is input the format XXX.X

I have used sed to add a backslash to the string as below:

SYMBOL_CODE=$(echo $SYMBOL_CODE|sed 's/[.]/\\./g')

As I said, the script actually seems to work but I was wondering if there was any way to suppress awk warnings? - other people will hopefully be using this script in production systems and I don't want them to see any warnings such as this...

Thanks

Try:

SYMBOL_CODE=$(echo $SYMBOL_CODE|sed 's/[.]/\\\\./g')

Or perhaps you could try this direct command instead:

awk -F\| '$1==s && $4=p' OFS=\| s="$SYMBOL_CODE" p="$NEW_PREV_CLOSE" PreviousClose2.asp >> EUTssPrevClose.txt

If it works then you can leave out all the escapes and you can use the original SYMBOL_CODE without the added backslashes...

1 Like

Yes, I tried this before, unfortunately it did not have an effect.

---------- Post updated at 09:38 AM ---------- Previous update was at 09:36 AM ----------

That's great. I still need a symbol code variable with the backslashes for another line, so I have created two version of the variable - one with, one without. Thanks very much