Finding the number of unique words in a file

find the number of unique words in a file using sort com-
mand.

grep -n "unique_word" file_name

---------- Post updated at 05:18 AM ---------- Previous update was at 05:15 AM ----------

sort -u your_file | wc -l
sort -u your_file | wc -l

this command gives all word's in the file.but not unique word

can you tell me what do you mean by the unique words.. it gives you all the unique lines in the file.

try:

tr ' ' '\n' < file | sort | uniq -c | wc -l

Modifying dazdseg's code:

xargs -n1 < your_file | sort -u | wc -l

The switch -u does not necessarily have the same meaning with all versions of sort on different OSes. GNU sort -u is filtering uniques, yes.

Assuming a unix format text file with multiple lines and one or more words per line. Words separated by space(s) and or tab(s).

cat filename|tr '\n' ' '|tr '\t' ' '|tr -s ' '|tr ' ' '\n'|sort|uniq|wc -l 

Change newline to space.
Change tab to space.
Change multiple spaces to one space.
Change space to newline.
sort.
Remove duplicates with "uniq".
Count the number of unique words.