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 1
s in the file? Thanks.
Use this :
tr -s ' ' '\n' < myfile.txt | grep -c '1'
Give this a try:
tr -dc 1 < inputfile | wc -c
精彩评论