Counts a number of unique word contained in the file and print them in alphabetical order

What should be the Shell script that counts a number of unique word contained in a file and print them in alphabetical order line by line?

what have you got so far? after 100+ posts you are not a shell newbie any more.

Not sure what you're looking for exactly. This will sort a file and give you the unique lines.

cat myfile | sort | uniq > outfile

If you are looking for something different, can you provide and example of the input file and then what you want the output to look like?

There is a file containing the following:

Process is a program under execution but thread is a light weight process which has separate way of execution.

The output should be like:

a
execution
but
has
is
light
of
process
program
separate
thread
under
way
weight
which

i.e., Determine unique word contained in the file and print them in alphabetical order line by line.

and so where is your code? what have you tried?

$ cat input-file
process is a program under execution but thread is a light weight process which has separate way of execution.
$ tr ' ' '\n' < input-file | sort | uniq
a
but
execution
execution.
has
is
light
of
process
program
separate
thread
under
way
weight
which

Anyway you have to answer the @ghostdog74 questions.

I think perl works nicely for this...

#!/usr/bin/perl

use strict;

my %seen;     # hash used to store how many times a word has been seen.
my @a_word;   # array to store uniq words.
my $word;     # variable to store each word.

#
# Loop through all lines in the file
#
while (<>)
{

   #
   # Split each line and proces each word.
   #
   for $word (split)
   {

      #
      # Change the word to lowercase.
      #
      $word = "\L$word";

      #
      # Create or increment the hash for the word.
      # This lets the hash act as a word counter as well.
      #
      $seen{$word}++;

      #
      # If this is the first time the word has been seen.
      # add the word to the arraw of words.
      #
      if ($seen{$word} == 1)
      {
         push( @a_word, $word );
      }
   }
}

#
# Sort the contents of the array of words.
#
@a_word = sort(@a_word);

#
# Print out each word and the number of times it was found.
#
foreach (@a_word)
{
   print "$_ $seen{$_}\n";
}

exit
#
# end of wc.pl
#

Sample Input Data

one two
two
three four
four
zabc
five
six Eight
seven
wdef
eight
nine
ten

Output

./wc.pl < sample.dat

eight 2
five 1
four 2
nine 1
one 1
seven 1
six 1
ten 1
three 1
two 2
wdef 1
zabc 1

Hope this helps.

Thanks all