Parameter value is not getting resolved

Hi,

I am using below command and its working fine:

$ zcat abc.dat.gz | awk -F\| 'NF==102{print NR,$0}'

but when I am using above command in script as below then temp_var2 is not getting resolved.

zcat "$1" | awk -F "$2" 'NF==$temp_var2{print NR,$0}'

Here, $1 and $2 are parameters which are passed while running script and temp_var2 I am creating inside which is getting assigned as numeric value.

Please help.

Shell variables are not expanded within single quotes.

Try something like this:

zcat "$1" | awk -F "$2" -v nrfields="$temp_var" 'NF==nrfields{print NR,$0}'
2 Likes

Thanks Scrutinizer!!
your command worked for me :slight_smile: