AWK Variable assignment issue Ksh script

Hi There,
I am writing a ksh script which assigns variable values from file "A" and passes that variables to file "B". While passing the parameters an additional "$" sign is being assigned to awk -v option.
Could any one help me with this please.

#!/bin/ksh
head -1 usr_soft_list_192.168.154.2.tmp |cut -d, -f2- |while read line
do
  sid=$(echo $line |cut -d, -f4)
  echo $sid
  vid=$(echo $line |cut -d, -f5)
  echo $vid
  dum=$(echo $line |cut -d, -f6)
  echo $dum
  cat std_soft.tmp |awk -F, -v var1=$sid -v var2=$vid -v var3=$dum '$5 == var1 && $6 == var2 && $7 == var3 {print }' >> x
done
exit

Below is the out put with for your referene

 ksh -x 1
+ head -1 usr_soft_list_192.168.154.2.tmp
+ cut -d, -f2-
+ read line
+ echo $'192.168.154.2,APPSRV1,AS,200,16016,jdk-6u20-linux-i586.bin\r'
+ cut -d, -f4
+ sid=200
+ echo 200
200
+ echo $'192.168.154.2,APPSRV1,AS,200,16016,jdk-6u20-linux-i586.bin\r'
+ cut -d, -f5
+ vid=16016
+ echo 16016
16016
+ echo $'192.168.154.2,APPSRV1,AS,200,16016,jdk-6u20-linux-i586.bin\r'
+ cut -d, -f6
+ dum=$'jdk-6u20-linux-i586.bin\r':wall:
+ echo $'jdk-6u20-linux-i586.bin\r'
jdk-6u20-linux-i586.bin
+ cat std_soft.tmp
+ awk -F, -v var1=200 -v var2=16016 -v var3=$'jdk-6u20-linux-i586.bin\r' '$5 == var1 && $6 == var2 && $7 == var3 {print }'
+ 1>> x
+ read line
+ exit

Not sure of the "$" symbol from the example you posted, can you "dos2unix" the files(usr_soft_list_192.168.154.2.tmp and std_soft.tmp) before using them in script?

1 Like

It was added by 'set -x', not awk. This is a ksh string literal:

a=$'some special \n\t chars'
echo "$a"

Thanks Panyam.. its wokring :slight_smile: