开发者

awk command within bash loop - recognizing double quote

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜