Module Modified Answers
Module Modified Answers
txt use
tabs to separate the fields.
Mytable.txt:
1425 ravi 15.65
4320 ramu 26.27
6830 sita 36.15
1450 raju 21.86
a. Use the cat command to display the file. Mytable.txt?
Output: sec-e@vignan:~$ cat Mytable.txt
1425 ravi 15.65
4320 ramu 26.27
6830 sita 36.15
1450 raju 21.86
b. Use the Vicomm and to correct any errors in the file.Mytable.txt?
Output:
c. Use the sort command to sort the file Mytable.txt according to the first field?
Output: sec-e@vignan:~$ sort Mytable.txt
1425 ravi 15.65
1450 raju 21.86
4320 ramu 26.27
6830 sita 36.15
d. Call the sorted file output.txt (different name)
Output: sec-e@vignan:~$ sort Mytable.txt > output.txt
sec-e@vignan:~$ sort -o output.txt Mytable.txt
sec-e@vignan:~$ cat output.txt
1425 ravi 15.65
1450 raju 21.86
4320 ramu 26.27
6830 sita 36.15
e. Print the file Mytable.txt?
Output: sec-e@vignan:~$ ip Mytable.txt
1425 ravi 15.65
4320 ramu 26.27
6830 sita 36.15
1450 raju 21.86
f. Use the cut & paste commands to swap fields 2 nd and 3 rd in Mytable.txt. Call it
Mytable.txt?
Output:
vignan@vignan:~$ cut -f1,3 mlq.txt > cat
vignan@vignan:~$ cut -f2 mlq.txt | paste cat -> result
vignan@vignan:~$ cat result
1425 15.65 ravi
4320 26.27 ramu
6830 36.15 sita
1450 21.86 raju
2. Write a shell script that displays a list of all the files in the current directory to which the
user has read, write and execute permissions.
Source Code:
#!/bin/bash
echo "List of files in current directory having read,write and execute permissions:"
for file in *
doif [ -f $file ]
then
if [ -r $file -a -w $file -a -x $file ]
then
ls -l $file
fi
fi
done
Output:
List of files in current directory having read,write and execute permissions:
-rwxrw-r-- 1 vignan vignan 37 Feb 3 08:40 a
-rwxrw-r-- 1 vignan vignan 111 Feb 3 08:43 d
-rwxrwxrwx 1 vignan vignan 139 Feb 3 08:59 permission.sh
-rwxrwxrwx 1 vignan vignan 114 Feb 3 08:57 permission.sh~
3. Write a shell script that computes the total and average marks of a student according to the
following;
● Ifaveragemarks≥69thenresultis-
● Ifaveragemarks≥59and≤
● Ifaveragemarks≥49and≤
● Note that any subject marks ≤ 40then result is-Fail ‖ .
Accept student name and six subject marks through the keyboard
Source code:
echo "Enter Student name"
read name
echo "Enter Student Registered Number"
read reg
echo "Enter the marks of five subjects : "
read m1 m2 m3 m4 m5
let total=$m1+$m2+$m3+$m4+$m5
let per=(total/5)
echo "Name :$name"
echo "Registered number :$reg"
echo "student total marks:$total"
echo "Student percentage :$per"
if [ $per -ge 69 ]
then
echo "grade :Distinction"
elif [ $per -ge 59-a $per -lt 69 ]
then
echo "Grade :First class"
elif [ $per -ge 49-a $per -lt 59 ]
then
echo "Grade :Pass"
else
echo "Grade :Fail"
fi
Output:
vignan@vignan:~/os$ ./hi.sh
Enter Student name
abc
Enter Student Registered Number
4200
Enter the marks of five subjects :
95 98 78 96 99
Name :abc
Registered number :4200
student total marks:466
Student percentage :93
grade :Distinction