I use a simple awk script to sum a value in a split of the fourth column. Works no problems.
awk '{split($4,NM,"-");if ($10>1) {TGC+=NM[2]}}END{print TGC}' somefile.txt
When I try to loop it in BASH, it runs, but gives an answer of one.
for i in somedir; do echo $i; awk '{split($4,NM,"-");if ($10>1) {TGC+=NM[2]}}END{print TGC}' $i ;done
The problem is in the quotes within the split - how can I properly qualify it so awk recognizes the split?
Ch开发者_如何学JAVAeers statler
I suspect you intended your for loop to examine the files in somedir, not the directory itself:
for i in somedir/*; do
echo "$i"
awk '
$10 > 1 {split($4, NM, "-"); TGC += NM[2]}
END {print TGC}
' "$i"
done
精彩评论