SORTING THE CONTENT OF THE FILE - Computer Programming

Latest

C C++ Java Python Perl Programs Examples with Output -useful for Schools & College Students

Wednesday, October 27, 2010

SORTING THE CONTENT OF THE FILE

To write a shell program to sort the given names in a file.


Algorithm:
1.Start the program
2.Get the file name in which sorting is to due
3.Enter the names to be sorted.
4.Using while loop, the names are compared using”>>’ and names are sorted
5.Display the sorted names.

Program:
echo “enter the file name”
read x
echo “enter the number of names”
read num
echo “enter $num strings” while test $num -gt 0
do
read name
echo $name >> $x
num = expr $num -1’
done
echo the sorted names are:
sort $x
rm $x

Output:
Enter the file name
Sort 1
Enter the number of names:
5

Enter 5 strings:
Computer
History
Biology
Maths



The sorted strings are:
Biology
Computer
Maths
History

No comments:

Post a Comment