Monday, January 20, 2014

Unix and Shell Programming - Sorting and Merging Files

with 0 Comment
clear
echo "Sorting and Merging Files"
echo "--------------------------------"
echo
while true
do
echo "Menu"
echo "------"
echo
echo "1.Sorting a File"
echo
echo "2.Merging a Two File"
echo
echo "3.Exit"
echo
echo "Enter your choice"
read c
case $c in

1)
echo  "Sorting a file"
echo  "----------------"
ls
echo
echo "Enter the file"
read f
echo "Before sorted"
echo "----------------"
echo
cat $f
echo "After Sorted"
echo "---------------"
sort -o f $f
cat f
echo
;;

2)
echo "Merging a two file"
echo "----------------------"
echo "Enter the first file name"
read f
echo "Enter the second file name"
read f1
echo "Before Sorted"
echo "----------------"
echo
echo "Contents of First file"
echo "-------------------------"
cat $f
echo "Contents of Second file"
echo "----------------------------"
cat $f1
echo
echo "After Sorted"
echo "---------------"
sort -o f $f
sort -o f1 $f1
echo "Sorted first file"
echo "------------------"
cat f
echo "Sorted Second file"
echo "----------------------"
cat f1
echo "After merging a two sorted files"
echo "--------------------------------------"
sort -m -o ans f f1
echo
cat ans
echo "End of sorting and merging file"
;;

3)
exit
esac
done

--------------
OUTPUT:
-------------
Sorting and Merging Files:
----------------------

Menu
-------
1.Sorting a File
2.Merging a two file
3.Exit

Enter our choice
1
Sorting a file
----------------
1    count1.sh    f    indu   priya3   selvi   trans.sh
a     count.sh     f1   Indu  ram   semi.sh  tr.sh
a2   d2    f3    mano    re  sort1.sh     vidhya

Enter the file
cmp

Before Sorted
-----------------
Madurai
Thrichy
Chennai
delhi
banglore

After Sorted
---------------
banglore
chennai
delhi
madurai
thrichy

Enter our choice
2

Merging a two file
-----------------------
Enter the first file name
cmp
Enter the second file name
cmp1
Before Sorted
-----------------
Contents of First File
-------------------------
Madurai
thrichy
chennai
delhi
banglore

Contents of Second file
----------------------------
madurai
thrichy
chennai
delhi
banglore

After Sorted
---------------
Sorted First File
-------------------
banglore
chennai
delhi
madurai
thrichy

Sorted Second file
----------------------
banglove
chennai
delhi
madurai
thrichy

After merging a two sorted files
--------------------------------------
banglore
banglore
chennai
chennai
delhi
delhi
madurai
madurai
thrichy
thrichy

End of Sorting and merging file

Enter our choice
3

0 comments:

Post a Comment

Powered by Blogger.

Blog Archive