Assuming you have the text file named Hamlet.txt:
Quote:
To be, or not to be, that is the question:
Whether 'tis nobler in the mind to suffer
The Slings and Arrows of outrageous fortune;
Or to take Armes against a Sea of troubles...
|
you could obtain the list of the words using the command:
cat Hamlet.txt | tr -cs A-Za-z0-9\\047 \\012
Quote:
To
be
or
not
to
be
that
is
the
question
Whether
'tis
nobler
in
the
mind
to
suffer
The
Slings
and
Arrows
of
outrageous
fortune
Or
to
take
Armes
against
a
Sea
of
troubles
|
to count the words you could use the following command:
cat Hamlet.txt | tr -cs A-Za-z0-9\\047 \\012 | grep '.' -n
since you'd like to know just the number of the words use the command:
cat Hamlet.txt | tr -cs A-Za-z0-9\\047 \\012 | grep '.' -n | tail -n 1 | cut -d ':' -f 1
The more effective method is to use mentioned above wc command but you refuse to use it.