Hi All,
I am performing addition of two inetger variables which assigning output to a new variable getting following error.
Check1.sh
#!/bin/ksh
filesrc=/usr/kk/Source1.txt
filetgt=/usr/kk/Source2.txt
FINAL_COUNTS= `awk '{n++} END {printf "%012d\n",n}' ${filesrc} ${filetgt}`
echo 'Final Count is:'$FINAL_COUNTS
Below is the output:
+ awk {n++} END {printf "%012d\n",n} /usr/kk/Source1.txt /usr/kk/Source2.txt
+ 000000000014
+ FINAL_COUNTS=
./Check1.sh[5]: 000000000014: not found.
aigles
2
Replace space before awk :
#!/bin/ksh
filesrc=/usr/kk/Source1.txt
filetgt=/usr/kk/Source2.txt
FINAL_COUNTS=`awk '{n++} END {printf "%012d\n",n}' ${filesrc} ${filetgt}`
echo 'Final Count is:'$FINAL_COUNTS
or add quotes if you wat a space before count in FINAL_COUNTS :
#!/bin/ksh
filesrc=/usr/kk/Source1.txt
filetgt=/usr/kk/Source2.txt
FINAL_COUNTS=" `awk '{n++} END {printf "%012d\n",n}' ${filesrc} ${filetgt}`"
echo 'Final Count is:'$FINAL_COUNTS
Jean-Pierre.
1 Like
Wouldn't this suffice?
FINAL_COUNT=`printf "%012d" $(cat $filesrc $filetgt | wc -l)`