LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   getting syntax error (https://www.linuxquestions.org/questions/linux-newbie-8/getting-syntax-error-4175511227/)

santosh0782 07-15-2014 11:53 PM

getting syntax error
 
Hi,

here is the piece of code where i am getting error:
Code:

for i in DCP KIVR CCCD
do
        ${i}_A=`grep "2014-07-14 06" $DATA_DIR/${i}_hourly_paya.txt|awk -F '|' '{printf "%-10d\n",$2}'`



        if [[ ! -n "${${i}_A}" ]]
        then
        echo 2014-07-14 06 0 >> $DATA_DIR/${i}_hourly_paya_TMP.txt
        else
        echo 2014-07-14 06 ${${i}_A} >> $DATA_DIR/${i}_hourly_paya_TMP.txt
        fi
done

output:

$ ./san_tst.sh
./san_tst.sh: line 4: syntax error at line 12: `!' unexpected

could someone please help?

evo2 07-16-2014 12:10 AM

Hi,

why are you trying to use such a convoluted identifier for your local variable. Can you not do something like:
Code:

for i in DCP KIVR CCCD
do
        a=`grep "2014-07-14 06" $DATA_DIR/${i}_hourly_paya.txt|awk -F '|' '{printf "%-10d\n",$2}'`



        if [[ ! -n "$a" ]]
        then
        echo 2014-07-14 06 0 >> $DATA_DIR/${i}_hourly_paya_TMP.txt
        else
        echo 2014-07-14 06 $a >> $DATA_DIR/${i}_hourly_paya_TMP.txt
        fi
done

There may be other issues but that's what jumped out first.

santosh0782 07-16-2014 12:37 AM

Thanks a lot :-). tried above provided,It is working fine now.. :-)


All times are GMT -5. The time now is 11:55 PM.