开发者

how to count appearance of '1' in a file

开发者 https://www.devze.com 2023-02-16 16:56 出处:网络
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 th

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

精彩评论

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

关注公众号