How do I count words in UNIX?

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?
  1. Using the grep command: $ grep -o ‘Unix’ file | wc -l 4. …
  2. tr command: $ tr -s ” ” “n” < file | grep -c Unix 4. …
  3. awk solution: $ awk ‘/Unix/{x++}END{print x}’ RS=” ” file 4. …
  4. Perl solution: $ perl -ne ‘$x+=s/Unix//g;END{print “$xn”}’ file 4. …
  5. Another Perl solution:
 

Tìm kiếm

Back
Top