Phương Linh
New member
How do I count words in UNIX?
Answer
How to find the total count of a word / string in a file?
Answer
How to find the total count of a word / string in a file?
- Using the grep command: $ grep -o ‘Unix’ file | wc -l 4. …
- tr command: $ tr -s ” ” “n” < file | grep -c Unix 4. …
- awk solution: $ awk ‘/Unix/{x++}END{print x}’ RS=” ” file 4. …
- Perl solution: $ perl -ne ‘$x+=s/Unix//g;END{print “$xn”}’ file 4. …
- Another Perl solution: