Using bash variables in awk

C_DATE=$(cat $1 |grep "Processing" | sed "s/[^0-9]//g" )</p>

cat $1 | awk 'BEGIN {RS="Data"; FS="\n";OFS=":" } {print $1,$5,$8,$9,$10}' | awk  'BEGIN {FS=":";OFS=":"}NR >1 {print $C_DATE,$1,$2,$3+0,"\tTotal Closed",$5+$7,$8,$9+0,"\tClosed%\t",(($5+$7)/$3)*100,"\tError%\t",($9/$3)*100  }

will not work

to use Bash variable in AWK you need to redefine the variable in awk using -v </div>

The option -v followed by var=value is an assignment to be  ( AWK MAN PAGE)

C_DATE=$(cat $1 |grep "Processing" | sed "s/[^0-9]//g" )</p>

#echo "$C_DATE"

cat $1 | awk 'BEGIN {RS="Data"; FS="\n";OFS=":" } {print $1,$5,$8,$9,$10}' | awk -v C_DATE="$C_DATE" 'BEGIN {FS=":";OFS=":"}NR >1 {print C_DATE,$1,$2,$3+0,"\tTotal Closed",$5+$7,$8,$9+0,"\tClosed%\t",(($5+$7)/$3)*100,"\tError%\t",($9/$3)*100  } '

</div>

comments powered by Disqus