Monday, January 20, 2014

Unix and Shell Programming - Database Manipulation

with 0 Comment
clear
echo "Database Manipulation"
echo "----------------------------"
echo "Database Creation"
echo "----------------------"
echo "Enter the File name"
read fn
echo "Content of the File"
echo "-----------------------"
cat $fn
while true
do
echo "Menu"
echo "-----"
echo "1.Cut"
echo "2.Paste"
echo "3.Sort"
echo "4.Merge"
echo "5.Exit"
echo "Enter our choice"
read ch
cae $ch in
1)
echo "Cut Command"
echo "------------"
echo "Cut Based on the File Position"
cut -c 1-3,20-$fn>name2
cat name2
;;

2)
echo "Paste Command"
echo "-------------------"
cat $fn
echo "Enter the field position -1"
read p1
cut -f $p1 $fn>name3
echo
echo "Enter the field position -2"
read p2
echo
cut -f $p2 $fn>name4
echo
echo "Pasting"
echo "--------"
paste name3 name4>name5
cat name5
;;


3)
echo "Sort Command"
echo "------------------"
echo "Before Sorting"
echo "------------------"
cat name2
echo
echo "After Sorting"
echo "----------------"
sort name2>sname2
cat sname2
;;

4)
echo "Merge File"
echo "-------------"
echo "Sorted File1"
echo "---------------"
cat sname2
echo "Sorted File2"
echo "---------------"
sort name4>sname4
cat sname4
echo "Merge Sorting"
echo "-----------------"
sort -m sname2 sname4
;;

5)
echo "No Choice"
exit
;;
esac
done

----------
Output:
----------
Datbase Manipulation
--------------------------
Databsae Creation
----------------------
Enter the file name
cmp

Content of the file
----------------------
madurai
thrichy
chennai
delhi
bangalore

Menu
-------
1.Cut
2.Paste
3.Sort
4.Merge
5.Exit

Enter our Choice
1

Cut Command
-----------------
Cut Based on the file position

mad
thr
che
del
ban

Enter our choice
2

Paste Command
-------------------
madurai
thrichy
chennai
delhi
banglore

Enter the field position -1
2

Enter the field position -2
5

Pasting
---------
madurai  madurai
thrichy    thrichy
chennai   chennai
delhi       delhi
banglore  banglore

Enter our choice
3
Sort Command
------------------
Before Sorting
------------------
mad
thr
che
del
ban

After Sorting
----------------
ban
che
del
mad
thr

Enter our choice
4

Merge File
-------------
Sorted File1
--------------
ban
che
del
mad
thr

Sorted file2
--------------
banglore
chennai
delhi
madurai
thrichy

Merge Sorting
-----------------
ban
banglore
che
chennai
del
delhi
mad
madurai
thr
thrichy

Enter our choice
5
No Choice

0 comments:

Post a Comment

Powered by Blogger.

Blog Archive