SORTING THE CONTENT OF THE FILE
Aim
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.
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
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
Sort 1
Enter the number of names:
5
Enter 5 strings:
Computer
History
Biology
Maths
The sorted strings are:
Biology
Computer
Maths
History
Biology
Computer
Maths
History
Result:
Thus the program is written and executed for sorting the content of the file.
0 comments:
Post a Comment