Source Code txt", "r") # reading data of the file read_data = file. read() # converting data in lower case and the counting the occurrence word_count = read_data. lower(). count(search_word_count) # printing word and it's count print(f"The word '{search_word_count}' appeared {word_count} times.")
Use the wc command to count the number of lines, words, and bytes in the files specified by the File parameter.
Wc Command in Linux (Count Number of Lines, Words, and Characters) On Linux and Unix-like operating systems, the wc command allows you to count the number of lines, words, characters, and bytes of each given file or standard input and print the result.
This will also count multiple occurrences of the word in a single line:
grep -o 'word' filename | wc -l
cat filename | tr ' ' '\n' | grep 'word' | wc -l
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With