I am trying to count the null records of a column in a file, subject to a condition. But the condition is not working.
- Example input: fixed width file,
761128424607/22/20197611284246CAD052020DHH 0073578EKLAVY3
ELEKBAFXXL7900271761128424406/22/20197611284244CAD042020DKA 0038244EDITTU8
761128424606/22/20197611284246CAD052020DHH 0073578EKLAVY3
ELEKBAFXXL7900271761128424406/22/20197611284244CAD042020DKA 0038244EDITTU8
- code
RE='[[:space:]]{17}' awk -v m=1 -v p=17 -v r='&& substr($0,28,2)==06' $'BEGIN{re = ENVIRON["RE"]}{c = substr($0,m,p)} c ~ "^(" re ")$" r {N++} END {print N+0}' < input_file.txt
- Desired output:
1
, since 2 records having null in file and out of this 1 record satisfies conditionsubstr($0,28,2)==06
- Actual output:
0
, which is wrong
awkscript="......"; awk "$awkscript"
. BTW, programs that generate code which is later executed are not unusual, but they do require even more care and attention to detail than usual.