Shell Script To Demonstrate 8 Simple Filter Commands | Edit Replace in File

Linux grep command is used to filter the particular word in the line. Using this command we can edit the file
Source Code Programming For Edit Delete Replace File using Linux grep command. Here we are using 8 filter command
The following shell script demonstrates the simple filter commands.
Description:
Command Used Description
head Used to display content from the top of the file.
tail Used to display content from the bottom of the file.
cut Used to cut the lines from the text files.
paste Used to paste the lines that are cut from the text files.
sort Used to sort the lines of the text file.
uniq Used to compare two sorted files line by line.
more Used to display all content of the file.
cmp Used to compare two files.
Source Code Programming For Edit Delete Replace File using Linux grep command
#Shell Script to demonstrate 8 simple filter commands
tput clear
n=1
while [ $n -ne 0 ]
do
clear
echo "MENU"
echo "1.to use head command"
echo "2.to use tail command"
echo "3.to use cut command"
echo "4.to use paste command"
echo "5.to use sort command"
echo "6.to use uniq command"
echo "7.to use more command"
echo "8.to use cmp command"
echo "Enter your choice"
read a
clear
case "$a" in
1) echo "Enter the name of the file"
read f1
if test -f $f1
then
echo "Enter the no of records we want to display"
read b
head -n $b $f1
else
echo "file does not exists"
fi
;;
2) echo "Enter the name of the file"
read f1
if test -f $f1
then
echo "Enter the no of records we want to display"
read b
tail -$b $f1
else
echo "file does not exist"
fi
;;
3) echo "Enter the name of file"
read f1
if test -f $f1
then
echo "Enter the field we want to cut"
read b
cut -d "|" -f $b $f1
else
echo "file does not exist"
fi
;;
4) echo "Enter the name of the file"
read f1
echo "Enter the name of the file we want to paste in"
read f2
if test -f $f1
then
paste $f1 $f2
cat 4f2
else
echo "file does not exist"
fi
;;
5) echo "Enter the name of the file"
read f1
if test -f $f1
then
sort $f1
else
echo "file does not exist"
fi
;;
6) echo "Enter the name of the file "
read f1
if test -f $f1
then
sort $f1 | uniq
else
echo "file does not exist"
fi
;;
7) echo "Enter the name of the file"
read f1
if test -f $f1
then
echo "more command"
more $f1
else
echo "file does not exist"
fi
;;
8) echo "Enter the name of the file"
read f1
echo "Enter the file we want to compare"
read f2
if test -f $f1
then
echo "cmp command"
cmp $f1 $f2
else
echo "file does not exist"
fi
;;
*) echo "Invalid option"
esac
echo "Do u want to continue(1 YES / 0 NO )"
read n
done
OutPut Bash Script Program

MENU
1.to use head command
2.to use tail command
3.to use cut command
4.to use paste command
5.to use sort command
6.to use uniq command
7.to use more command
8.to use cmp command
Enter ur choice
1
Enter the name of the file
f2
Enter the no of records we want to display
1
i am doing study
Do u want to continue(1 YES / 0 NO )
1
MENU
1.to use head command
2.to use tail command
3.to use cut command
4.to use paste command
5.to use sort command
6.to use uniq command
7.to use more command
8.to use cmp command
Enter ur choice
2
Enter the name of the file
file2
Enter the no of records we want to display
1
Where r u going dear???
CONCLUSION: Linux Bash Script

Related post