linux 系统 awk命令统计字符出现的次数

1、测试数据

root@PC1:/home/test/test# cat a.txt
w d t
d g e
t c d
root@PC1:/home/test/test# awk -v RS="@#$j" '{print gsub(/d/,"&")}' a.txt    ##RS是输出分割符,定义特殊分隔符,系统把数据看作是一行,gsub统计次数
3

 

awk统计每行中特定字符出现的次数

补充:

root@PC1:/home/test/test# cat a.txt
w d t
d g e
t c d
root@PC1:/home/test/test# awk '{print gsub(/t/,"&")}' a.txt
1
0
1

 

相关文章

Centos系统之Shell编程基础知识
从Export理解Shell环境和变量生存期
linux shell数组变量、类型及规则
Centos编程Shell基本工作原理方案
Centos操作系统编程之Shell 问答录
rsync-linux备份脚本