awk统计行数

awk 统计文件中满足特定条件的行数


例 文件tt.txt
sdfasf,I,55,56,asdfadf223
sdfasf,I,55,56,asdfadf2230k
1313,I,55,56,asdfad
xvxzv,I,55,56,asdf
adfa,a,d,afasd
vafasf,fff,aw,aaa
fasf,a,55,56,asdf
asdcc,I,55,fasdf,33
asdfasdf,I,fa,56,adsf


统计已逗号为分割的第二列为“I”,第三列为“55”,第四列为“56” 的行数,并输出已第一列为的各行及对应出现次数 到文本sum.txt
awk 'BEGIN{FS=",";}{if($2=="I" && $3=="55" && $4=='56') a[$1]++} END{for (i in a) print i,a[i];}' tt.txt >sum.txt  
或统计./diraa 目录下各个文件满足条件的
awk 'BEGIN{FS=",";}{if($2=="I" && $3=="55" && $4=='56') a[$1]++} END{for (i in a) print i,a[i];}' ./diraa/* >sum.txt


你可能感兴趣的:(linux)