DOS Assignment 2
DOS Assignment 2
Q1. Write a shell script named as prog for merge the content of files a.txt, b.txt,
and c.txt sort them and save the result in a file called result and display the
sorted output on the screen.
(Note: a.txt, b.txt and c.txt file contain some numerical value. Make the script
an executable file and run it as a command using its name only.)
Command:
cat > a.txt
cat > b.txt
cat > c.txt
cat > prog.sh
sort -n a.txt b.txt c.txt > result.txt
^C
chmod a+x prog.sh
./prog.sh
cat result.txt
Output:
Q2. Write a shell script named as systeminfo that will display the information
about the login name of the user, name of the Unix system used by the user,
type of the SHELL, Path of current working directory of the user and list of file
contain in current working directory. (Make the script an executable file and
run it as a command using its name only.)
Command:
cat > systeminfo.sh
echo $USERNAME
uname
echo $SHELL
pwd
ls -l
^C
chmod a+x systeminfo.sh
./systeminfo.sh
Output:
Q3. Write a shell script named as dtcal for displaying both the system date and
calendar for specific month, say march 2022, in the given format:-
Date: current date
Calendar: specific calendar
(Make the script an executable file and run it as a command using its name
only.).
Command:
cat > dtcal.sh
date=`date`
calendar=`cal 03 2022`
echo “Date: $date”
echo “Calendar: $calendar”
^C
chmod a+x dtcal.sh
./dtcal.sh
Output:
Q4. Write a shell script named as nvwc which will display the filename and
linecount, wordcount and char count of the file dtcal in the following format:
Filename: dtcal
Line count: -
Word count: -
Char count: -
(Make the script an executable file and run it as a command using its name
only.)
Command:
cat > nvwc.sh
filename= “dtcal”
linecount=`wc -l dtcal.sh`
wordcount=`wc -w dtcal.sh`
charcount=`wc -m dtcal.sh`
echo “Filename: $filename”
echo “Line count: $linecount”
echo “Word count: $wordcount”
echo “Char count: $charcount”
^C
chmod a+x nvwc.sh
./nvwc.sh
Output:
Q5. Write a shell script named as nvwc2 which will display the filename and
linecount, word count and char count of any file given as argument to nvwc2
in the following format:
filename linecount wordcount charcount
file1 - - -
(Make the script an executable file and run it as a command using its name
only.)
Command:
cat > nvwc2.sh
filename= “$1”
linecount=`wc -l $filename`
wordcount=`wc -w $filename`
charcount=`wc -m $filename`
echo “filename linecount wordcount charcount”
echo “$filename $linecount $wordcount $charcount”
Output:
Q6. Write a shell script named as darg to display the total number of command
line arguments along with the first two arguments.
-Modify the script to display all the arguments.
(Make the script an executable file and run it as a command using its name
only.)
Command:
cat > darg.sh
echo “Total number of arguments: $#”
echo “First argument: $1”
echo “Second argument: $2”
^C
chmod a+x darg.sh
./darg.sh arg1 arg2
Output:
Modification to display all the arguments:
Command:
cat > darg.sh
echo “Total number of arguments: $#”
echo “All the arguments are: $*”
^C
chmod a+x darg.sh
./darg.sh arg1 arg2 arg3 arg4 argx
Output:
Q7. Write a shell script named as ndisp that will take three command line
arguments specifying the value of n, m and a filename and display the first n
number of lines and last m number of lines of the file given as argument.
(Make the script an executable file and run it as a command using its name
only.)
Command:
cat > file.txt
Hello,
This is
Vivek
Kumar
Mohanta
2141013166
^C
cat > ndisp.sh
n=$1
m=$2
filename=$3
head -n $n $filename
tail -n $m $filename
^C
chmod a+x ndisp.sh
./ndisp.sh 3 2 file.txt
Output: