How can I use the UNIX shell to count the number of times a letter appears in a text file?

后端 未结 10 711
清酒与你
清酒与你 2021-02-03 19:07

I have a few text files and I\'d like to count how many times a letter appears in each?

Specifically, I\'d like to use the UNIX shell to do this, in the form of: cat fil

10条回答
  •  不要未来只要你来
    2021-02-03 19:50

    Here is another way

    cat  input_file | \
    awk 'BEGIN {FS="x"; var=0 } \
    {if (NF>0){ var=var + (NF-1) } } \
    END{print var}'
    

    where X is the character or string of characters you want to count and infile is the input file

提交回复
热议问题