Unix Prog
Unix Prog
$ read num
$ if [ $num -gt 0 ]
$ then
$ fi
$ read num
$ if [ $num -gt 0 ]
$ then
$ else
$ fi
$ read num
$ if [ $num -gt 0 ]
$ then
$ then
$ echo “num is equal to zero”
$ else
$ fi
Write a Shell Script that takes a search string and file name from the terminal & displays the results.
read a
read b
word= `grep $a $b`
if test `echo $word |wc –c`-eq 1
then
echo “patern not found”
else
grep $a $b
fi
Write a Shell Script that takes pattern and file name as command line arguments and displays the results
appropriately i.e. pattern found/pattern not found.
if test $# -ne 2
then
echo “Invalid no. of arguments”
else
word=’grep $1 $2
if test ‘word | wc –c’ –eq1
then
echo ”pattern not found ”
else
grep $1 $2
echo “pattern found”
fi
fi
Write a Shell Script that accepts only three arguments from the command line. The first argument is the pattern
string, the second argument is the file name in which the pattern is to be searches and the third argument is the
file name in which the result is to be stored.
if test $# -ne3
then echo “Invalid no. of arguments”
else
grep $1 $2 | cat>$3
if test –s $3
then
echo “pattern found”
cat $3
else
echo “pattern not found”
fi
________________________________________
echo "STRING MANIPULATION PROGRAM"
echo "1. COMPARE STRING"
echo "2. JOINT TWO STRING"
echo "3. LENGTH OF STRING"
echo "4. OCCOURANCE OF CHARACTER"
echo "5. OCCOURANCE OF WORD"
echo "6. REVERSE STRING"
echo "ENTER CHOICE:"
read ch
case $ch in
1)
echo "ENTER FIRST STRING:"
read str1
echo "ENTER SECOND STRING:"
read str2
len1=`echo $str1 | wc -c`
len2=`echo $str2 | wc -c`
if [ $len1 -eq $len2 ];then
echo "BOTH STRINGS ARE OF SAME LENGTH"
elif [ $len1 -gt $len2 ];then
echo "$str1 is greater than $str2"
else
echo "$str2 is greater than $str1"
fi
;;
2)
echo "ENTER FIRST STRING:"
read str1
echo "ENTER SECOND STRING:"
read str2
str1="$str1$str2"
echo "COMBINED STRING : $str1"
;;
3)
echo "ENTER STRING:"
read str
len=`echo $str | wc -c`
echo "Length of string is $len"
;;
4)
echo "ENTER STRING:"
read str
echo "ENTER character of word to search:"
read search
len=`echo $str | wc -c`
i=1
while [ $i -lt $len ]
do
ch=`echo $str | cut -c $i`
echo $ch
i=`expr $i + 1`
done
;;
6)
echo "ENTER STRING:"
read str
echo "REVERSE STRING IS : "`echo $str | rev`
;;
*)
echo "ENTER PROPER CHOICE"
echo "NOT THERE"
;;
Esac
clear
echo -----------------------------------
echo '\tCompare two files'
echo -----------------------------------
echo Enter the name of the First file
read first
echo Enter the name of the Second file
read second
cmp $first $second