0% found this document useful (0 votes)
24 views9 pages

Sqlkab2 1

Uploaded by

kharatmaldhruv
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views9 pages

Sqlkab2 1

Uploaded by

kharatmaldhruv
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

1)A.

Write a shell script to print contains of file from given line number to next given

number of lines

echo "Enter the file name :"

read f

echo "Enter the starting line :"

read s

echo "Enter the ending line :"

read e

sed -n $s,$e\p $f

B. create a Linux shell script program to add two numbers.

a=10

b=20

sum=$(( $a + $b ))

echo $sum

----------------------------------------------------------------------------------------------------------------------

2). A. create a Linux shell script program to swap two numbers.

first=5

second=10
temp=$first

first=$second

second=$temp

echo "After swapping, numbers are:"

echo "first = $first, second = $second"

B. Write a Shell script to find whether entered year is Leap or not.

echo "Enter a y"

read y

if [‘expr $y%4’ -eq 0];

then

echo "$year is a leap year."

else

echo "$year is not a leap year."

fi

-------------------------------------------------------------------------------------------------------------------------

3A. Write a program to add 2 nos. supplied as command line arguments.

read a

read b

sum=$(( $a + $b ))

echo "Sum is: $sum"


B. create a Linux shell script program to multiply two numbers.

read a

read b

sum=$(( $a * $b ))

echo "Sum is: $sum"

-------------------------------------------------------------------------------------------------------------

4A. Write a program to add 2 nos. supplied as command line arguments.

read a

read b

sum=$(( $a + $b ))

echo "Sum is: $sum"

Write a program to find out biggest number from given three nos.

#!/bin/bash

echo "Enter three numbers: "

read a

read b

read c

if [ $a -gt $b -a $a -gt $c ]

then

echo $a is the biggest number

elif [ $b -gt $a -a $b -gt $c ]

then
echo $b is the biggest number

else

echo $c is the biggest number

fi

----------------------------------------------------------------------------------------------------------------------

5A. create a Linux shell script program to print program name using command-line.

#!/bin/bash

# Program name: "script_name.sh"

# shell script program to print program name using command line argument.

echo Script program Name: $0

B. WAP to Calculate average of given numbers. (50, 100, 150)

echo "Enter numbers to find their average (space-separated): "

read a

read b

read c

sum=$(echo “$a + $b + $c” | bc -l)

avg=$(echo “$sum/3” | bc -l)

echo “sum = $sum”

echo “Average = $avg”

------------------------------------------------------------------------------------------------------------------

A. create a Linux shell script program to create and print the value of variables.

country="India"

year=2021
echo "Country name: $country"

echo "Year: $year"

B. Write script to print given number in reverse order, for eg. If no is 123 it must print

as 321. (use while loop).

echo "enter the number "

read num

while [ $num != 0 ]

do

d=$(($num % 10 ))

num=$(($num / 10 ))

rev=$( echo ${rev}${d} )

done

echo $rev

-----------------------------------------------------------------------------------------------------------------

Write a Shell script to say Good morning/Afternoon/Evening as you log in to

system.

hour=$(date +%H)

if [ $hour -lt 12 ]; then

greet="Good morning"

elif [ $hour -le 18 ]; then

greet="Good afternoon"

else

greet "Good evening"

fi

echo “$greet”

------------------------------------------------------------------------------------------------------------------

Write a script to print following print.(use for loop)


echo "Enter the number of rows: "

read n

for((i=1; i<=n; i++))

do

for((j=1; j<=n-i; j++))

do

echo -n " "

done

for((j=1; j<=2*i-1; j++))

do

echo -n "*"

done

echo ""

done

for((i=n-1; i>=1; i--))

do

for((j=1; j<=n-i; j++))

do

echo -n " "

done

for((j=1; j<=2*i-1; j++))

do

echo -n "*"

done

echo ""

done

(for diamond)
For inverted pattern

----

-------------------------------------------------------------------------------------------------------------------

A. Explain find and grep command with example.

grep -i -o word filename.txt | wc -l

B. Calculating factorial of given number.

echo “Enter a number”


read num
fact=1
while[ $num -gt 1]
do fact=$((fact * num))
num=$((num - 1))
done
echo $fact
-------------------------------------------------------------------------------------------------------
B. Converting decimal number to hexadecimal number.

echo "enter number"


read n
c=$(echo "obase=16;$n" | bc)
echo hexadecimal $c

----------------------------------------------------------------------------------------------------------------------

i. Program to check whether given file is a directory or not.

echo "Enter the name of the file"

read var

if [ -d $var ]

then

echo "The provided argument is the directory."


#Using -f option we are checking whether the first argument is a file or not.

elif [ -f $var ]

then

echo "The provided argument is the file."

#if the provided argument is not file and directory then it does not exist on the system.

else

echo "The given argument does not exist on the file system."

fi

ii. program to count number of files in a Directory.

echo "Enter the name of the directory"

read var

ls "$var"|wc -l

--------------------------------------------------------------------------------------------------------------------------

B. calculate the total count of occurrences of a particular word in a file.

grep -i -o word filename.txt | wc -l

------------------------------------------------------------------------------------------------------
B. write an awk script to find the no of characters, words and lines in a file.

BEGIN{}
{
print len=length($0),"\t",$0
wordcount+=NF
chrcnt+=len
}
END {
print "total characters",chrcnt
print "Number of Lines are",NR
print "No of Words count:",wordcount
}

-------------------------------------------------------------------------------------------------------------------

. B. write an awk script to count number of lines in a file that does not contain vowels.
echo "Enter file name"
read file
awk '$0!~/[aeiou]/{ count++ }
END{print "The number of lines that does not contain vowels are: ",count}' $file

-------------------------------------------------------------------------------------------------

A. Write a perl script to compute power of a given number.

for($i=1;$i<10 ;$i++ )

printf $i^2 . "\n";

----------------------------------------------------------------------------------------------------------------

You might also like