How to count the occurences of a specific word in a file in bash shell


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to count the occurences of a specific word in a file in bash shell
# 1  
Old 10-30-2008
Bug How to count the occurences of a specific word in a file in bash shell

Hello,

I want to count the occurences of a specific word in a .txt file in bash shell.

Can somebody help me pleaze??

Thanks!!!
# 2  
Old 10-30-2008
Code:
tr -s ' ' '\n' < myfile.txt | grep -c 'searchword'

# 3  
Old 10-30-2008
Thanks a lot it really works!
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Count occurences of the word without it repeating

Hi, I would like to count the number of ALA occurences without having them to be repeated. In the script I have written now it has 40 repetitions of ALA but it has to be 8. ALA is chosen as one of the 20 values it can have when the script asks for the input of AAA, which for this example is chosen... (7 Replies)
Discussion started by: Aurimas
7 Replies

2. Shell Programming and Scripting

Count occurences of a character in a file by sorting results

Hello, I try to sort results of occurences in an array by using awk but I can't find the right command. that's why I'm asking your help ! :) Please see below the command that I run: awk '{ for ( i=1; i<=length; i++ ) arr++ }END{ for ( i in arr ) { print i, arr } }' dictionnary.txt ... (3 Replies)
Discussion started by: destin45
3 Replies

3. UNIX for Dummies Questions & Answers

How do I count how many times a specific word appear in a file (ksh)?

Hi Please can you help how do I count the number of specific characters or words that appear in a file? (8 Replies)
Discussion started by: fretagi
8 Replies

4. UNIX for Dummies Questions & Answers

Number of word occurences in a file?

Hello world, Can anybody tell me how to count how many times does a word repeat in a file? There have been many threads on this but they all are heavy loads of Scripting for a starter like me. :D So, I sat down today and after some hours of reading man pages, I found a simple one-line... (18 Replies)
Discussion started by: satish51392111
18 Replies

5. UNIX for Advanced & Expert Users

Count specific word or character per line

Hi, I need help regarding counting specific word or character per line and validate it against a specific number i.e 10. And if number of character equals the specific number then that line will be part of the output. Specific number = 6 Specific word or char = || Sample data:... (1 Reply)
Discussion started by: janzper
1 Replies

6. Shell Programming and Scripting

To search a file for a specific word in a file using shell script

Hi All, I have a sql output file has below. I want to get the values 200000040 and 1055.49 .Can anyone help me to write a shell script to get this. ACCOUNT_NO ------------------------------------------------------------ BILL_NO ... (8 Replies)
Discussion started by: girish.raos
8 Replies

7. UNIX for Dummies Questions & Answers

Count number of occurences of a word

I want to count the number of occurences of say "200" in a file but that file also contains various stuff including dtaes like 2007 or smtg like 200.1 so count i am getting by doing grep -c "word" file is wrong Please help!!!!! (8 Replies)
Discussion started by: shikhakaul
8 Replies

8. HP-UX

count occurences of specific character in the file

For counting the occurences of specific character in the file I am issuing the command grep -o 'character' filename | wc -w It works in other shells but not in HP-UX as there is no option -o for grep. What do I do now? (9 Replies)
Discussion started by: superprogrammer
9 Replies

9. Shell Programming and Scripting

Help with scritp to count an specific word into a log

Hello my friends, I need to count how many words are into a log file, I'm using: cat logfile | grep 'word' | wc -l Cuz the 'word' appears once per line. But my logfile grow faster and at the end ofthe day is really big, so how i can count the 'word' only from (by example) line 4000 of... (5 Replies)
Discussion started by: lestat_ecuador
5 Replies

10. Shell Programming and Scripting

grep and count no of occurences in every line of a file

Hi Folks, I have a input file of the below format. ~~~OLKIT~OLKIT~1~~TBD~BEST PAGER & WIRELESS~4899 COMMON MARKET PLACE~~~DUBLIN~KS~43016~I~Y~DIRECT~D~~0 BPGRWRLS~~~OLKIT~OLKIT~1~~TBD~BEST PAGER & WIRELESS~4899 COMMON MARKET PLACE~~~DUBLIN~KS~43016~I~Y~DIRECT~D~~0... (12 Replies)
Discussion started by: srikanthgr1
12 Replies
Login or Register to Ask a Question