Professional Documents
Culture Documents
Linux File
Linux File
File Of
LINUX
ROLL NO - 07
SECTION-A
INDEX
1. Write a Shell program, which accepts the name of a file from the standard input
and perform the following tests on it:
(i) File existence
(ii) File readable
(iii) File writeable
(iv) Both readable and writeable
2. Write a Shell program using 3 arguments to take the pattern as well as input and
output file names. If the pattern is found display "pattern found", else display
"Error message". Also check if right of argument is entered.
3. Write a Shell program , which accepts the name of the file from the standard
input and the performs the following operation:
(i) Enter the 5 names in a file
(ii) Sort the names in existing file
(iii) List unsorted and sorted file
(iv) Quit
4. Write a menu driven Shell program to copy, edit, rename, and delete a file.
5. Write a menu driven Shell program to the performs the following tasks:
(i) Enter the sentence in file
(ii) Search a given whole word in an existing
file
(iii) Quit
6. (a) Write a Shell program to prepare the electricity bill based on the following
rules: For first 100 units - Rs. 1.00/unit For next 100 units - Rs. 2.00/unit Above
200 units - Rs. 3.00/unit
(b) Write a Shell program to prepare the electricity bill based on the following
rules: For first 100 units - Rs. 0.75/unit For next 100 units - Rs. 1.50/unit Above
200 units - Rs. 3.00/unit
7. Write a Shell program to sum up the following series: (1 /1!) + (2/2!) + (3/3!) + ----
-
8. (a) Write a Shell script to display the result "PASS" or "FAIL" using the
information given below: Student Name, Student Register number, Marks 1 ,
Marks 2, Marks 3, Marks 4. The minimum pass for each subject is 50.
(b) Write a Shell script to display the result of a student in neat format using the
information given below: Student Name, Student Register Number, Marks 1 ,
Marks 2, Marks 3, Marks 4. The minimum pass for each subject is 50.
9. Write a menu driven Shell script for converting all the capital letters in a file to
small case letters and vice versa.
10. Write a Shell script for a file contains record with each containing name of city,
state, country . How would you sort this file with country as primary sort key and
state as the secondary sort key.
11. Write a Shell script to merge the contents of three given files, sort them and
display the sorted output screen page by page. Display the list of 20 files present
in the current directory. Also store this list in a file name-profile.
12. Write a Shell script to Enhance the cp command to copy files. Display the
necessary error message if error occurs.
13. Write a Shell script to check the user is eligible for vote or not. (one must attain
18 years for voting. Ignore month differences.)
14. Write a Shell script to do the following on the files of the current directory based
on file extensions.
• Move all the C language files into the subdirectory -c
• Move all the Shell file files into the subdirectory -shell
• Move all the Java files into the subdirectory - java
• Move all the Text files into the subdirectory - text
15. Write a Shell script to check whether a given string is Palindrome or not.
1. Write a Shell Program which accepts the name of a file from the standard input and
performs the following test on it:
i) File existence
ii)File readable
iii)File writeable
iv)Both readable and writeable
if test -r $filename
then
echo "file is readable"
else
echo "file is not readable"
fi
if test -w $filename
then
echo "file is writeable"
else
echo "file is not writeable"
fi
output:
Write a Shell Program using 3 arguments to take the pattern as well as input and the
output file names. If the pattern is found display “Pattern found”, else display “Error
message”. Also check if right number of arguments is entered.
if test $# -eq 3
then
ifgrep "$1" $2 > $3
then
echo "pattern found "
echo " the content of the output file is :"
cat $3
else
echo "pattern not found "
fi
else
echo " Argument are not correctly passed "
fi
3. Write a Shell Program which accepts the name of a file from the standard input and
performs the following test on it:
i)Enter the five name in the file
ii)Sort the names in existing file
iii)List unsorted and sorted file
iv)Quit
choice=y
while test $choice = y
do
echo -n "Menu:
1. Copy
2. Edit
3. Rename
4. Delete
Enter your choice :"
readch
echo "enter source filename"
read source
case $ch in
1) echo " enter the target file name"
read target
cp $source $target
;;
2) vi $source
;;
3) echo "enter the new name "
read target
mv $source $target
;;
4) rm $source
;;
esac
echo -n " do you want to continue [y/n] "
read choice
Done
Before applying any operation the files are as follows:-
choice=y
while test $choice = y
do
echo -n " Menu:
1. Enter the sentence in file
2. Search the word
3. Exit
Enter your choice :"
readch
case $ch in
1) echo -n "enter the file name "
readfname
echo "enter the whole sentence "
cat> $fname
;;
2) echo -n "enter the file name "
readfname
echo "enter the word you want to search"
read word
grep "$word" $fname|| echo "word not found"
;;
3) exit
;;
esac
echo -n "do you want to continue [y/n] "
read choice
done
6. (a) Write a Shell program to prepare the electricity bill based on the following rules:
For first 100 units - Rs. 1.00/unit
For next 100 units - Rs. 2.00/unit
Above 200 units - Rs. 3.00/unit
#! /bin/sh
echo "Enter units"
read a
if [ $a -le 100 ]
then
then
d=`expr $a -100`
c=`expr $d \* 2 + 100`
else
d=`expr $a - 200`
c=`expr $d \* 3 + 300`
fi
(b) Write a Shell program to prepare the electricity bill based on the following rules:
For first 100 units - Rs. 0.75/unit
For next 100 units - Rs. 1.50/unit
Above 200 units - Rs. 3.00/unit
#! /bin/sh
read a
if [ $a -le 100 ]
then
e= `expr $a \* 0.75`
then
d=`expr $a -100`
else
d=`expr $a - 200`
c=`expr $d \* 3 + 225`
fi
7. Write a Shell script to sum up the following series:
( 1 / 1!) + ( 2 / 2!) + ( 3 / 3!)+……
echo -n "How many terms ? "
read n
fact=1
cnt=1
sum=0
if [ $m1 -ge 50 ]
then
r1=" PASS "
else
r1=" FAIL "
fi
if [ $m2 -ge 50 ]
then
r2=" PASS "
else
r2=" FAIL "
fi
if [ $m3 -ge 50 ]
then
r3=" PASS "
else
r3=" FAIL "
fi
if [ $m4 -ge 50 ]
then
r4=" PASS "
else
r4=" FAIL "
fi
9. Write a menu driven Shell Script for converting all capital letter in a file to small letter
and vice versa.
choice=y
while test $choice = y
do
echo -n "Menu
1. UPPERCASE TO LOWERCASE
2. LOWERCASE TO UPPERCASE
Enter your choice : "
readch
echo -n "Enter Source File name :"
read s
echo -n "Enter target file name :"
read t
case $ch in
1) dd if=$s of=$t conv=lcase
;;
2) dd if=$s of=$t conv=ucase
;;
esac
echo -n "Do you want to continue [y/n] "
read choice
done
Before operation:-
After operation:-
10. Write a Shell script for a file contains record with each record containing name of a city,
name of state and name of county. How would you sort this file with country as the
primary sort key and state as the secondary sort key.
11. Merge the content of three given file, sort them and display the sorted output on the
screen page by page.
Display the list of last 20 files present in the current directory. Also store this list in a file
name –profile.
Output:--
12. Enhance the copy command to copy files. Display the necessary error message if error
occurs.
if test $# -eq 0
then
echo " specify Source and Destination filename "
elif test $# -eq 1
then
echo " specify Destination filename "
elif test $# -gt 2
then
echo " more than enough argument "
elif test ! -e $1
then
echo " source file doesnot exists "
elif test -d $1
then
echo " source is a directory not file"
elif test ! -r $1
then
echo " source file is not readable "
elif test -e $2 -a ! -w $2
then
echo " Destination file is not writeable "
elif test -f $2
then
echo " Destination file exists. Overwrite [y|n] "
readch
if test $ch = y
thencp $1 $2
fi
fi
13. Write a Shell script to check if the user is eligible for vote or not.(age > 18)
cyear=`date +%Y`
age=`expr $cyear - $year`
for file in *
do
case $file in
*.c) mv $file $HOME/c;;
*.sh) mv $file $HOME/shell;;
*.txt) mv $file $HOME/text;;
*.java) mv $file $HOME/java;;
esac
done
15. Write a Shell script to check whether a given string is palindrome or not.