Monday, January 20, 2014

Unix and Shell Programming - tr Command

with 0 Comment
clear
echo "Tr Commands"
echo "-----------------"
echo
echo "Enter the file name"
echo
read f
if[-f $f]
then
while true
do
echo
echo "Menu"
echo "-------"
echo
echo "1.Delete"
echo
echo "2.Squeeze"
echo
echo "3.Complement"
echo
echo "4.Exit"
echo
echo "Enter your choice"
echo
read n
case $n in
1)
echo "Delete"
echo "-------"
echo
echo "Content of the file"
echo "----------------------"
cat $f
echo "Enter the Character to be deleted"
read d
echo "After Deletion"
echo "------------------"
tr -d $d<$f
;;

2)
echo "Squeeze"
echo "----------"
echo
echo "Content of the file"
echo "----------------------"
cat $f
echo "Enter the Character to be changed"
read old
echo "After Squeeze"
echo "-----------------"
tr -s $old <$f
;;

3)
echo "Complement"
echo "----------------"
echo "Content of the file"
echo "----------------------"
cat $f
echo "Enter the Character not be changed"
read com
echo "Enter the replacing character"
read rep
echo "After Complement"
echo "-----------------------"
tr -c $com $rep<$f
;;

4)
echo "No Choice"
echo
exit
;;
esac
done
else
echo "File does not exit"
fi

-------------
OUTPUT:
-------------
Tr Commands
-----------------
Enter the file name
tr

Menu
-------
1.Delete
2.Squeeze
3.Complement
4.Exit

Enter your choice
1

Delete
--------
Content of the file
----------------------
A Friend is need the friend indeed

Enter the character to be deleted
e

After Deletion
------------------
A friend is nd th friend indd

Enter your choice
2

Squeeze
----------
Content of the file
----------------------
A friend is need the friend indeed

Enter the character to be changed
ee

After Squeeze
-----------------
A friend is ned the friend inded

Enter your choice
3

Complement
----------------
Content of the file
----------------------
A friend is need the friend indeed.

Enter the character not be changed
i

Enter the replacing character
-
After Complement
----------------------
---i---i--------------i---i------

Enter your choice
4
No Choice

0 comments:

Post a Comment

Powered by Blogger.

Blog Archive