#!/bin/bash
awk_script_file="/data/shell/scf_tmp.$$"
#here,getline读取没一行数据,通过内部for循环,借助match函数,累计的数据,存放在数组中;
cat<<'EOF'>$awk_script_file
BEGIN{
while(getline < "./testfile" > 0){
for (i=1;i<=NF;++i){
if(match($i,"^[a-zA-Z]+$") != 0)
arr[$i]++
}
}
for(word in arr){
printf "word=%s\tcount=%s\n",word,arr[word]
}
}
EOF
#awk 执行
awk -f $awk_script_file
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/26855487/viewspace-773620/
,如需转载,请注明出处,否则将追究法律责任。