5

awk variable issue

view full story
linux-howto

http://www.linuxquestions.org – Hi , i have problem with awk variable. I am able to get variable for $pname and $powner when i tried to echo them. However i keep having syntax error in "print owner1" , and FYI this is my first time to assign 2 variable in 1 awk line. Any comment? thanks! Source file sample Code: /abc patrick /cdf John /ghi Colin My Code Code: N=0 while read LINE ; do         N=$((N+1)) pname=`echo $LINE | cut -f1 -d' '` powner=`echo $LINE | cut -f2 -d' '` #echo $pname" belongs to " $powner find $pname -atime +30 -exec ls -lk '{}' \; | awk  -v p=$pname -v owner1=$powner '{SUM += $5} END { if (SUM == "") print p " | " print owner1 " | 0.0" ;else print p " | " print owner1 " | " sprintf("%.1f",SUM/1048576)}' >> $localdb #find $pname -atime +30 -exec ls -lk '{}' \; done < $sourcefile Error Message: Code: awk: cmd. line:1: {SUM += $5} END { if (SUM == "") print p " | " print owner1 " | 0.0" ;else print p " | " print owner1 " | " sprintf("%.1f",SUM/1048576)} awk: cmd. line:1:                                                ^ syntax error awk: cmd. line:1: {SUM += $5} END { if (SUM == "") print p " | " print owner1 " | 0.0" ;else print p " | " print owner1 " | " sprintf("%.1f",SUM/1048576)} awk: cmd. line:1:                                                                                          ^ syntax error find: ls terminated by signal 13 find: ls terminated by signal 13 find: ls terminated by signal 13 (HowTos)