for a text like the following:
std_out_file: ${ALGO_TOP}/dynamic/batchlog/JS030003-ara.stop.badb.out
I want the output to be:
$BATCHLOG_DIR/JS030003-ara.stop.badb.out
here is the code:
nawk '/std_out_file:|std_err_file:/ { split($2, a, /); if ( a[3]=="batchlog" ) print "$$BATCHLOG_DIR/"$3; else print "$$CONSOLELOG_DIR/"$3; }'
I got the following error:
nawk: illegal primary in regular expression ); if ( a[3]=="batchlog" ) print "$$BATCHLOG_DIR at ; if ( a[3]=="batchlog" ) print "$$BATCHLOG_DIR
source line number 4
context is
/std_out_file:|std_err_file:/ { split($2, a, /); if ( a[3]=="batchlog" ) print "$$BATCHLOG_DIR/", $3; else print >>> " <<<
where did I get it wrong?
The third argument of
splitfunction is a regex. You should place your/insidesplitfunction like:Notice that
/needs to be escaped to letawkknow that is it not start or end of theregexpattern.Having said that, you can avoid the
splitaltogether by setting the delimiter to/. Something like:Where you test the second last field
$(NF-1)to bebatchlog. The ternary op is basically doing the same thing as yourif-elsecondition.