LINUX PROGRAMMING LAB MANUAL
LINUX PROGRAMMING LAB MANUAL
WEEK3
Programs:
AIM: 5. Write a Shell script that accepts a list of file names as its arguments, counts and
reports the occurrence of each word that is present in the first argument file on other argument
files.?
THEORY:
Tr: The Tr command can be used for to translate the characters that means the given string is
replaced with the replacement string.
Syntax: Tr [original string] [replacement string]
Grep: The Grep command can be used for to search the regular pattern on given file.
Syntax: Grep [ pattern ] file name
if [ $# -eq 0 ]
then
echo "no arguments"
else
tr " " "
" < $1 > temp
shift
for i in $*
do
tr " " "
" < $i > temp1
y=`wc -l < temp`
j=1
while [ $j -le $y ]
do
x=`head -n $j temp | tail -1`
c=`grep -c "$x" temp1`
echo $x $c
j=`expr $j 1`
done
done
fi
# !/bin/bash
echo "enter directory name"
read dir
if[ -d $dir]
then
echo "list of files in the directory"
ls –l $dir|egrep „^d‟
else
echo "enter proper directory name"
fi
# !/bin/bash
echo "enter a number"
read num
fact=1
while [ $num -ge 1 ]
do
fact=`expr $fact\* $num`
num=‟expr $num – 1‟
done
echo "factorial of $n is $fact"
VIVA QUESTIONS
1.why we are using grep command?
2.what is an shell script?
3.why we are using egrep command?
4.what is the purpose of fgrep?
5.write a syntax of grep?
6.what is an shell variable?