0% found this document useful (0 votes)
29 views

Sqllab

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)
29 views

Sqllab

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

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

hour=$(date +%H)
if (( hour >= 5 && hour < 12 )); then
echo "Good morning"
elif (( hour >= 12 && hour < 18 )); then
echo "Good afternoon"
else
echo "Good evening"
fi

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


echo "Enter a year:"
read year

if (( $year % 4 == 0 && $year % 100 != 0 || $year % 400 == 0 )); then


echo "$year is a leap year."
else
echo "$year is not a leap year."
fi

simple calculator

# !/bin/bash

# Take user Input


echo "Enter Two numbers : "
read a
read b

# Input type of operation


echo "Enter Choice :"
echo "1. Addition"
echo "2. Subtraction"
echo "3. Multiplication"
echo "4. Division"
read ch

# Switch Case to perform


# calculator operations
case $ch in
1)res=`echo $a + $b | bc`
;;
2)res=`echo $a - $b | bc`
;;
3)res=`echo $a \* $b | bc`
;;
4)res=`echo "scale=2; $a / $b" | bc`
;;
esac
echo "Result : $res"

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


#!/bin/bash

# Ask the user to enter the first number


echo "Enter the first number:"
read num1

# Ask the user to enter the second number


echo "Enter the second number:"
read num2
# Add the two numbers
sum=$((num1 + num2))

# Print the sum


echo "The sum of $num1 and $num2 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 -gt $c ]


then
echo "$a is the biggest number"
elif [ $b -gt $a ] && [ $b -gt $c ]
then
echo "$b is the biggest number"
else
echo "$c is the biggest number"
fi

WAP to Calculate average of given numbers.


#!/bin/bash

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


read -a nums
sum=0
for i in "${nums[@]}"
do
sum=$((sum + i))
done

avg=$((sum / ${#nums[@]}))
echo "The average is: $avg"

Write script to print given number in reverse order, for eg. If no is 123 it must print as 321. (use
while loop).
if [ $# -ne 1 ]
then
echo "Usage: $0 number"
echo " I will find reverse of given number" echo " For eg. $0 123, I will print 321" exit 1
fi
n=$1
rev=0
sd=0
while [ $n -gt 0 ]
do
sd=`expr $n % 10`
rev=`expr $rev \* 10 + $sd`
n=`expr $n / 10`
done
echo "Reverse number is $rev"

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


echo "Stars"
for (( i=1; i<=5; i++ ))
do
for (( j=1; j<=i; j++ ))
do
echo -n " *"
done
echo ""
done
for (( i=5; i>=1; i-- ))
do
for (( j=1; j<=i; j++ ))
do
echo -n " *"
done
echo ""
done
MAX_NO=0
echo -n "Enter Number between (5 to 9) : "
read MAX_NO
if ! [ $MAX_NO -ge 5 -a $MAX_NO -le 9 ] ; then echo "I ask to enter number between 5 and 9, Okay"
exit 1
fi
for (( i=1; i<=MAX_NO; i++ ))
do
for (( s=MAX_NO; s>=i; s-- ))
do
echo -n " "
done
for (( j=1; j<=i; j++ ))
do
echo -n " ."
done
echo ""
done
for (( i=MAX_NO; i>=1; i-- ))
do
for (( s=i; s<=MAX_NO; s++ ))
do
echo -n " "
done
for (( j=1; j<=i; j++ ))
do
echo -n " ."
done
echo ""
done
echo -e "\n\n\t\t\tI hope you like it my stupidity (?)"

write a program to check wether given file is in 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
program to count no. of file in directory

echo "Enter the name of the directory"


read var
ls "$var"|wc -l

write a shell script to print contains of file from given line num to next given line num

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

write a perl script to compute factorial of a given number

$number = 5; # Change the number here


$fact = 1;
for( $i = 1; $i <= $number ; $i=$i+1 ){
$fact = $fact*$i;
}
print "Factorial of $number is: $fact"

square a number in Perl


#square

for($i=1;$i<10 ;$i++ )
{
printf $i^2 . "\n";
}

Creating variable
#!/usr/bin/perl
@ages = (25, 30, 40);
@names = ("John Paul", "Lisa", "Kumar");
print "\$ages[0] = $ages[0]\n";
print "\$ages[1] = $ages[1]\n";
print "\$ages[2] = $ages[2]\n";
print "\$names[0] = $names[0]\n";
print "\$names[1] = $names[1]\n";
print "\$names[2] = $names[2]\n";
$age = 25; # An integer assignment
$name = "John Paul"; # A string
$salary = 1445.50; # A floating point
print "Age = $age\n";
print "Name = $name\n";
print "Salary = $salary\n";
write an awk script to find the no of characters, words and lines in a file .(online compiler)

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
}
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

write a sed program to print duplicated lines of input

sort filename | sed '$!N; s/^\(.*\)\n\1$/\1/; t; D'

write a sed program to dectect duplicated words

sed -n '/\([a-z][a-z]*\) \1/p' filename

decimal to hex

echo "enter number"


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

calculate total count of occurences of a particular word in a file


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

You might also like