Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有这样的数据,每行固定数量的字符(8)
RYRYRYRR YRRRRYRR YYRRRRRY RYYRRRRR RRRRRRRY RYRRRRRY
我需要分别输出计数“Y”和“R”的数量,如下所示..
RYRYRYRR 3 5 YRRRRYRR 2 6 YYRRRRRY 3 5
我已经尝试了使用 grep 的脚本,如下所示..
grep -c 'Y'test.dat 打印一些数字,如 13
试试这个:
awk '{print $0, gsub("Y", "Y"), gsub("R", "R")}'
在 awk 中,gsub 返回成功替换的次数。