How do I count the number of occurrences of a string in an entire file?

前端 未结 6 875
夕颜
夕颜 2020-12-21 02:17

Is there an inbuilt command to do this or has anyone had any luck with a script that does it?

I am looking to count the number of times a certain string (not word) a

6条回答
  •  遥遥无期
    2020-12-21 02:30

    You can use basic grep command:

    Example: If you want to find the no of occurrence of "hello" word in a file

    grep -c "hello" filename
    

    If you want to find the no of occurrence of a pattern then

    grep -c -P "Your Pattern"
    

    Pattern example : hell.w, \d+ etc

提交回复
热议问题