Linux Lab Progs Executed
Linux Lab Progs Executed
Page 1 of 4
1) write a shell script that accepts filename,starting and ending line as arguments and displays all
the lines between them.
if [ $# -lt 3 ]
then
echo "enter vlaid no. of arguments i.e, Filename,starting line,endind line no."
exit 1
fi
if [ ! -e $1 ]
then
echo "file doeasnt exists"
exit 1
fi
a=`expr $2 + 1 `
b=`expr $3 - 1 `
#head -$b $1 | tail -n +$a
sed -n "$a,$b p" $1
---------------------------------------------------------------------2)write a shell script that deletes all the lines containing a specified word in one or more files
supplied as arguments.
if [ $# -eq 0 ]
then
echo "enter sufficient arguments i.e, <word> <filenames>"
exit 1
fi
n=$1
shift
for i in $*
do
grep -v $n $i>temp
mv temp $i
echo $n
echo $i
done
sh second.sh sumi filename1 filename filename3
---------------------------------------------------------------------3) write sh script that displays a list of all the files in the current directory to which the user
has read,write and execute permissions.
for i in *
do
if [ -x $i -a -w $i -a -r $i ]
then
echo $i
fi
done
---------------------------------------------------------------------shellscript is used to receives of file names as arguments checks if every argument supplied is a file
or a directory and reports accordingly. Whenever the argument is a file, the number of lines on it is
also reported.
for i in *
do
if [ -d $i ]
then
echo $i is a directory
fi
if [ -f $i ]
then
echo " $i --fi
done
--------------------------------------------------------------------write a shell script that accepts a list of names as its arguments,counts and reports the occurance of
each word that is present in the first argument file on other argument files
n=$1
Page 2 of 4
Page 3 of 4
Page 4 of 4