linu
linu
n=0
echo Number at odd position
read -p "Enter a number : " n
echo $n
l=${#n}
i=1
echo The odd position numbers are
while [ $i -le $l ]
do
d=$(echo $n | cut -c $i)
echo -n $d " "
((i= i + 2))
Done
if [[ "$ch" =~ [ABCDEFGHIJKLMNOPQRSTUVWXYZ] ]]
then
echo The character is UPPERCASE
elif [[ "$ch" =~ [a-z] ]]
then
echo The character is Lowercase
elif [[ "$ch" =~ [0-9] ]]
then
echo The character is a Digit
elif [[ "$ch" =~ ['!@#\$%^\&*()_-+'] ]]
then
echo it is a Special Character
else
echo Nothing matching....
fi
function fact() {
local n=$1
if [[ $n -eq 0 ]]; then
echo 1
else
echo $((n*$(fact $n-1)))
fi
}
echo program to find the sum of series
echo enter the upper limit
read n
sum=0
for ((i=1;i<=n;i++))
do
sum=`expr "$sum + ($i / $(fact $i))" |bc`
done
echo "sum n series is $sum"
while :
do
clear
echo The program to List, Display, Make Dir, Copy and Rename File printf "\nSELECT
YOUR OPTION\n"
echo "1. List Directory"
echo "2. Create Directory"
echo "3. Copy Files"
echo "4. Display Files"
echo "5. Rename a File"
echo "6. Delete a file"
echo "7. Exit from program"
echo "Enter your menu choice [1-7]: "
read choice
case $choice in
1) ls
read -p "Press any key...: " ;;
2) echo "Enter The Directory Name"
read dirName
mkdir $dirName;
echo Directory Created...
read -p "Press any key...: " ;;
3) read -p "Enter name of the file to be copied :" fname read -p "Enter the name of the new
file :" newname cp $fname $newname
echo File copied...
read -p "Press any key...: " ;;
4) echo Enter the file name to be read
read fname
cat $fname
read -p "Press any key...: " ;;
5) echo Enter the file name
read fname
echo Enter the new name to be renamed
read newname
mv $fname $newname
echo file renamed...
read -p "Press any key...: " ;;
6) echo Enter the file name
read fname
rm $fname
echo file deleted...
read -p "Press any key...: " ;;
7) echo "Quitting ..."
exit;;
*) echo "invalid option";;
esac
done
while :
do
clear
printf "\nSELECT YOUR OPTION\n"
echo "1. Contents of /etc/passwd"
echo "2.list of OUTPUT: 'who'"
echo "3. Present working directory"
echo "4. Exit from program"
echo "Enter your menu choice [1-7]: "
read choice
case $choice in
1) cat etc/passwd
read -p "Press any key...: " ;;
2) who
read -p "Press any key...: " ;;
3) pwd
read -p "Press any key...: " ;;
4) echo "Quitting ..."
exit;;
*) echo "invalid option";;
esac
done
len=${#@}
if [ $len -eq 0 ]
then
echo No arguments please use with two arguments
exit
else
file1=$1
file2=$2
if [ -f $file1 -a -f $file2 ]
then
echo The file Comparison Program
if cmp -s "$file1" "$file2"
then
printf 'The file "%s" is the same as "%s"\n'"$file1" "$file2"
read -p "do you want to delete the second file y/n " chk
if [ "$chk" = "y" ]
then
rm $file2
echo The second duplicate file deleted...
fi
else
printf 'The file "%s" is different from "%s"\n'"$file1" "$file2"
fi
else
echo "File(s) not exists!"
fi
fi
len=${#@}
if [ $len -eq 0 ]
then
echo No arguments please use with some arguments
exit
else
echo Check files exists or not Program
for i in $@
do
if [ -e $i ]
then
echo $i " file exists "
else
echo $i " File not Exists "
fi
done
fi
while :
do
clear
echo
echo "
"
echo Student Management System
echo "
"
printf "\nSELECT YOUR OPTION\n"
echo "1. Add Record"
echo "2. View All Records"
echo "3. View a Record"
echo "4. Delete a Record"
echo "5. Exit from program"
echo "Enter your menu choice [1-5]: "
read choice
case $choice in
1) echo "enter rollnumber of student "
read number
echo "enter name of student "
read name
echo "enter marks Subject1 "
read sub1
echo "enter marks Subject2 "
read sub2
echo "enter marks Subject3 "
read sub3
total=`expr "$sub1 + $sub2 + $sub3" |bc`
record="$number,$name,$sub1,$sub2,$sub3,$total"
echo $record >> stud_data.dt
read -p "Press any key...: " ;;
2) printf "Number \tName\tSubject1\tSubject2\tSubject3\tTotal\n"
while read line
do for j in $line do
sno=$(echo "$j" | cut -d "," -f 1)
snm=$(echo "$j" | cut -d "," -f 2)
sub1=$(echo "$j" | cut -d "," -f 3)
sub2=$(echo "$j" | cut -d "," -f 4)
sub3=$(echo "$j" | cut -d "," -f 5)
total=$(echo "$j" | cut -d "," -f 6)
done printf '%s\t%s\t\t%s\t%s\t\t%s\t\t%s\n' "$sno" "$snm"
"$sub1" "$sub2" "$sub3" "$total"
done < stud_data.dt
read -p "Press any key...: " ;;
3) read -p "Enter the Student Number " csno
while read line
do for j in $line do 27
sno=$(echo "$j" | cut -d "," -f 1)
snm=$(echo "$j" | cut -d "," -f 2)
sub1=$(echo "$j" | cut -d "," -f 3)
sub2=$(echo "$j" | cut -d "," -f 4)
sub3=$(echo "$j" | cut -d "," -f 5)
total=$(echo "$j" | cut -d "," -f 6)
done
if [ $csno -eq $sno ]
then break
fi done < stud_data.dt
if [ $csno -eq $sno ] then
printf "Number \tName\tSubject1\tSubject2\tSubject3\tTotal\n"
printf '%s\t%s\t\t%s\t%s\t\t%s\t\t%s\n' "$sno" "$snm" "$sub1"
"$sub2" "$sub3" "$total"
else
echo No records found
fi
read -p "Press any key...: " ;;
4) echo "enter roll number "
read rn
grep ^$rn stud_data.dt
if [ $? -ne 0 ]; then
echo "record for roll number does not exist "
else
grep -v $rn stud_data.dt > tmp
cp tmp stud_data.dt
echo "deletion complete "
fi read -p "Press any key...: " ;;
5) echo "Quitting ..."
exit;;
*) echo "invalid option";;
esac
done
function fact()
{local n=$1
if [[ $n -eq 0 ]]; then
echo 1
else
echo $((n*$(fact $n-1)))
fi
}
#Factorial function
echo
echo The Factorial Program with Function
echo Enter the number
read number
echo The factorial is $(fact $number)
function palindrome
(){local input=$1
reverse=""
len=${#input}
for ((i=$len-1; i>=0; i-- ))
do
reverse="$reverse${input:$i:1}"
done
if [ $input == $reverse ]
then
echo the word $input is palindrome
else
echo the word $input is not palindrome
fi
}
echo The Palindrome Checking Program
read -p "Enter the Word to check " word
echo $(palindrome $word)
len=${#@}
echo
echo The File and Directory checking program
if [ $len -eq 0 ]
then
echo No arguments please use with some arguments
exit
else
echo Check files exists or not Program
for i in $@
do
#-e Returns true value if file exists.
if [ -d $i ]
then
echo $i " is a Directory"
else
echo $i " is a file "
echo -n and the number of lines are:
wc -l < $i
fi
done
fi
len=${#@}
echo
echo Count Lines and Words program
if [ $len -eq 0 ]
then
file="myfile.txt"
echo No files provided...
echo Enter text and press ctrl+d to save
cat >> $file
else
file=$1
fi
echo -n The number of lines are:
wc -l < $file
echo -n and the number of words are:
wc -w < $file
len=${#@}
echo File copying program
if [ $len -eq 0 ]
then
echo No arguments please use with some arguments
exit
elif [ `expr $len % 2` -eq 0 ]
then
for ((i=1; i<$len; i+=2))
do
if [ -f ${!i} ]
then
((j=i+1))
cp ${!i} ${!j}
echo Files Copied ${!i} to ${!j}
else
echo ${!i} " File not Exists "
fi
done
else
echo you are entered odd files
echo Error!!
Fi