0% found this document useful (0 votes)
8 views37 pages

OSP6

The document describes a shell script that allows a user to perform various file operations like comparing files, finding differences between files, concatenating files, and viewing directory trees. The script uses tools like cmp, comm, diff, cat, and tree to perform these operations and prompts the user to select which operation to perform.

Uploaded by

mitaleeextra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views37 pages

OSP6

The document describes a shell script that allows a user to perform various file operations like comparing files, finding differences between files, concatenating files, and viewing directory trees. The script uses tools like cmp, comm, diff, cat, and tree to perform these operations and prompts the user to select which operation to perform.

Uploaded by

mitaleeextra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 37

NAME: Mitalee Vaghasia

ROLL NO.: 22BCE190


PRACTICAL NO.: 5
COURSE: Operating System
AIM:
METHODOLOGY FOLLOWED:
while [ true ]
do
echo "Enter an operation number"
echo " 1) Compare the contents of the file using cmp"
echo " 2) Compare the contents of the file using common"
echo " 3) Get steps to make the contents of the files same using diff"
echo " 4) Concatenate two files into a single file"
echo " 5) Show tree view of a directory"
echo " 6) Other commands using cat"
echo " 7) Exit"
read opr
case $opr in
1) echo "Enter specific operation setting:"
echo "0) Compare using normal cmp command"
echo "1) Compare byte by byte (print differing bytes)"
echo "2) Compare after skipping first n bytes of both files"
echo "3) Compare after skipping first n bytes of file 1 and m bytes of file2"
echo "4) Compare and output byte numbers and differing byte values"
echo "5) Exit"
read ch
echo "Enter file 1 name: "
read f1
echo "Enter file 2 name: "
read f2
case $ch in
0)cmp $f1 $f2;;
1)cmp -b $f1 $f2;;
2)echo "Enter n:"
read n
cmp -i $n $f1 $f2
;;
3)echo "Enter n:"
read n
echo "Enter m:"
read m
cmp -i $n:$m $f1 $f2
;;
4)cmp -l $f1 $f2;;
5) echo "Exiting"
exit;;
esac
;;
2) echo "Enter specific operation setting:"
echo "0) Compare using normal comm command"
echo "1) Show unique content of file 2 and common content of both files, suppressing unique content of file 1"
echo "2) Show unique content of file 1 and common content of both files, suppressing unique content of file 2"
echo "3) Show unique content of file 1 file 2, suppressing common content of both files"
echo "4) Show output a summary of unique contents of file 1 and 2 with common content of both files"
echo "5) Exit"
read ch
echo "Enter file 1 name: "
read f1
sort $f1
echo "Enter file 2 name: "
read f2
sort $f2
case $ch in
0)comm $f1 $f2;;
1)comm -1 $f1 $f2;;
2)comm -2 $f1 $f2;;
3)comm -3 $f1 $f2;;
4)comm --total $f1 $f2;;
5) echo "Exiting"
exit;;
esac
;;
3) echo "Enter specific operation setting:"
echo "0) Compare using norma diff command to make 2 files similar"
echo "1) Compare using normal diff to make 2 directories similar"
echo "2) Recursively compare any subdirectories found in 2 directories"
echo "3) Compare by ignoring case differences in file contents"
echo "4) Compare and tell whether or not the 2 files differ"
echo "5) Compare and output an RCS format diff"
echo "6) Exit"
read ch
echo "Enter file/directory 1 name: "
read f1
echo "Enter file 2/directory name: "
read f2
case $ch in
0)diff $f1 $f2;;
1)diff $f1 $f2;;
2)diff -r $f1 $f2;;
3)diff -i $f1 $f2;;
4)diff -q $f1 $f2;;
5)diff -n $f1 $f2;;
6) echo "Exiting"
exit;;
esac
;;
4) echo "Enter specific operation setting:"
echo "0) Concatenate content of file 1 and 2 in file 3"
echo "1) Concatenate content of file 1 and 2 in file 3 with a $ line separator at the end"
echo "2) Concatenate content of file 1 and 2 in file 3 and number all output lines"
echo "3) Concatenate content of file 1 and 2 in file 3 and number nonempty output lines, overrides option 2"
echo "4) Concatenate content of file 1 and 2 in file 3 and suppress repeated empty output lines"
echo "5) Concatenate content of file 1 and 2 in file 3 in a sorted order"
echo "6) Exit"
read ch
echo "Enter file 1 name: "
read f1
head $f1
echo "Enter file 2 name: "
read f2
head $f2
echo "Enter file 3 name: "
read f3
case $ch in
0)cat $f1 $f2 > $f3
head $f3;;
1)cat -E $f1 $f2 > $f3
head $f3;;
2)cat -n $f1 $f2 > $f3
head $f3;;
3)cat -b $f1 $f2 > $f3
head $f3;;
4)cat -s $f1 $f2 > $f3
head $f3;;
5)cat $f1 $f2 | sort > $f3
head $f3;;
6) echo "Exiting"
exit;;
esac
;;
5) echo "If tree is not installed, use command sudo snap install tree"
echo "Enter directory name: "
read dn
tree $dn
;;
6) echo "Enter specific operation setting:"
echo "0) Show contents of a file"
echo "1) Show contents of multiple files"
echo "2) Create a file and input data"
echo "3) Show paged output using more if content of file is large"
echo "4) Show contents of a file with line numbers"
echo "5) Show contents of a file and display TAB characters as ^I"
echo "6) Redirect the standard output of a file into a new file else existing file (will OVERWRITE content in file2)"
echo "7) Redirect the standard output of a file into a new file else existing file (will APPEND content in file2)"
echo "8) Exit"
read ch

case $ch in
0)echo "Enter file name: "
read f1
cat $f1
;;
1)echo "Enter file 1 name: "
read f1
echo "Enter file 2 name: "
read f2
cat $f1 $f2
;;
2)echo "Enter file name: "
read f1
cat > $f1
;;
3)echo "Enter file name: "
read f1
cat $f1 | more
;;
4)echo "Enter file name: "
read f1
cat -n $f1
;;
5)echo "Enter file name: "
read f1
cat -T $f1
;;
6)echo "Enter file 1 name: "
read f1
echo "Enter file 2 name: "
read f2
cat $f1 > $f2
;;
7)echo "Enter file 1 name: "
read f1
echo "Enter file 2 name: "
read f2
cat $f1 >> $f2
;;
8)echo "Exiting"
exit;;
esac
;;
7) echo "Exiting"
exit
;;
*) echo "Enter valid data"
;;
esac
done
INPUT/OUTPUT:
COMPARE CMD
COMMON CMD
DIFF CMD
CAT CMD
TREE CMD
OTHER CAT CMDS

You might also like