001、
[root@localhost test]# ls a.txt [root@localhost test]# cat a.txt ## 测试数据 0aa1 0AA2 03 04 05 06 07 08 09 10 1a1 12 [root@localhost test]# awk '{a = gsub("[Aa]", ""); print a}' a.txt ## 统计每行中A或者a出现的次数 4 0 1
。
002、
[root@localhost test]# ls a.txt [root@localhost test]# cat a.txt ## 测试数据 0aa1 0AA2 03 04 05 06 07 08 09 10 1a1 12 [root@localhost test]# awk -F "[Aa]" '{print NF - 1}' a.txt ## 指定输入分割符,利用分割的字段来统计 4 0 1 [root@localhost test]# awk 'BEGIN{FS = "A|a"} {print NF - 1}' a.txt ## 指定输入分隔符 4 0 1
。