开发者

how to count appearance of '1' in a file

I have a file consisting of multiple lines of

b b b b b b ... b

where b is binary which can be 0开发者_Python百科 or 1. How can I write bash scripts to count number of 1s in the file? Thanks.


Use this :

tr -s ' ' '\n' < myfile.txt | grep -c '1'


Give this a try:

tr -dc 1 < inputfile | wc -c
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜