Thursday, February 3, 2011

The punctuation of parsing

Awk scripts when interacting with shell tend to be problematic. Reason awk assumes a different parsing criteria which is incompatible with the shell's own expectation. For e.g: The quotes and whitespaces (',"," ") have a definitive meaning in korn shell, which conflicts with awks. Running the script with
 set -x 
flag shows the details.

So a script snippet that would work on command line

awk 'BEGIN {RS="_EOL@"}' 'END {print $NF}" a.txt


is to be transformed to:

ETL_RECORD_DELIMITER="_EOL@"
cmd=`awk BEGIN{RS="\"$ETL_RECORD_DELIMITER\""}" "END{print" "NR} a.txt`


The white spaces are to be demarcated using " ", if you missed the gist.

No comments:

Post a Comment