Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added all scripts in the syllabus #14

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions Sem1/Unix_Programming/script_10a.awk
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
split( $0, inpt, "-")
if ((inpt[1] < 1) || (inpt[1] > 31) || (inpt[2] < 1) || (inpt[2] > 12))
{
print "Invalid Date!"
exit 0
}
else
{
switch (inpt[2])
{
case 1: print "Jan"
break
case 2: print "Feb"
break
case 3: print "Mar"
break
case 4: print "Apr"
break
case 5: print "May"
break
case 6: print "Jun"
break
case 7: print "Jul"
break
case 8: print "Aug"
break
case 9: print "Sep"
break
case 10: print "Oct"
break
case 11: print "Nov"
break
case 12: print "Dec"
break
}
print inpt[1]
print inpt[3]
exit 0
}
}
27 changes: 27 additions & 0 deletions Sem1/Unix_Programming/script_10b.awk
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
BEGIN{
printf("\nOriginal FIle\n")
i=1
}
{
print $0
line[i++]=$0
}
END{
for(j=1; j<i; j++)
{
for(k=j+1; k<i; k++)
{
if (line[j]==line[k])
{
line[k]=""
}
}
}
printf("\n The file after deleting duplicate lines\n")
for(k=1; k<i; k++)
{
if(line[k]!="")
printf("\n"line[k])
}
printf("\n")
}
15 changes: 15 additions & 0 deletions Sem1/Unix_Programming/script_11a.awk
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
BEGIN{
print "Total number of books sold in each category"
}
{
books[$1]+=$2
}
END{
for(item in books)
{
printf("\t%-17s %1s %-5d \n", item, "=", books[item])
total+=books[item]
}
printf("%-17s %1s %-5d \n","Total Books Sold ", "=", total)
}

28 changes: 28 additions & 0 deletions Sem1/Unix_Programming/script_11b.awk
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
BEGIN {
FS=":"
printf("\n\t\tsalary statement of employees for the month\n")
printf("sl.no\tname\t\tdesignation\tBASIC\tDA\tHRA\tGROSS\n")
print
}
{
slno++; basic_tot+=$5;
if ( $5 >= 10000 )
{
da=0.45*$5; da_tot+=da;
hra=0.15*$5;hra_tot+=hra;
}
else
{
da=0.50*$5;da_tot+=da;
hra=0.20*$5;hra_tot+=hra;
}
sal_tot+=$5 + da + hra
printf("%2d\t%-15s %12-s %8d %8.2f %8.2f %8.2f\n",slno,$2,$3,$5,da,hra,$5+da+hra)
}
END{
printf( "\n\ttotal basic paid is : rs " basic_tot)
printf( "\n\ttotal da paid is : rs " da_tot)
printf( "\n\ttotal hra paid is : rs " hra_tot)
printf( "\ntotal salary paid is : rs " sal_tot)
printf("\n")
}
15 changes: 15 additions & 0 deletions Sem1/Unix_Programming/script_1a.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

if [ $# -eq 1 ]
then
if [ -e $1 ]
then
echo "Larget File in the directory: $(find $1 -printf '%k %p\n' | sort -nr | head -n 1 | cut -d " " -f 2)"

else
echo "Path does not exist! Please check the path."
exit 0
fi
else
echo "This script takes only one valid directory name as an arguement!"
fi
9 changes: 9 additions & 0 deletions Sem1/Unix_Programming/script_1b.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#! /bin/bash

if [ $# -eq 1 ]
then
mkdir -pv $1
else
echo "This Script is only programmed to take one arguement as an input!"
fi

22 changes: 22 additions & 0 deletions Sem1/Unix_Programming/script_2a.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash

if [ $# -eq 2 ]
then

PERM1=$(stat --printf=”%a” $1)
PERM2=$(stat --printf=”%a” $2)

if [ "$PERM1" = "$PERM2" ]
then
echo Both the files have same permissions: $(stat --printf="%A" $1)
else
echo The given files have different permissions
echo "$1 : $(stat --printf="%A" $1)"
echo "$2 : $(stat --printf="%A" $2)"
fi
else
echo "This script is programmed to use two files in order
to compare their permissions"

fi

17 changes: 17 additions & 0 deletions Sem1/Unix_Programming/script_2b.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

if [ $# -eq 0 ]
then
echo "Run this script with one or more username(s) as arguement!"
else
for i in $*
do
if [ $(grep $i /etc/passwd) ]
then
echo "Home directory for $i: "
eval "echo ~$i"
else
echo "user does not exsist"
fi
done
fi
18 changes: 18 additions & 0 deletions Sem1/Unix_Programming/script_3a.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

if [ $# -ne 1 ]
then
echo "Run this cript with only one filename as arguement!"
else
if [ -f "$1" ]
then
echo "Name : $1"
echo "Permissions : $(stat --format="%A" $1)"
echo "Type: $(stat --format="%F" $1)"
echo "Owner: $(stat --format="%U" $1)"
echo "Group: $(stat --format="%G" $1)"
echo "Size: $(stat --format="%s" $1)"
else
echo "File does not exsist"
fi
fi
38 changes: 38 additions & 0 deletions Sem1/Unix_Programming/script_3b.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/bash

while true
do
clear
echo "**Password entered will not visible for security reasons**"
echo "Enter Password: "
read -s passFirst
echo "Re-enter Password: "
read -s passConfirm

if [ "$passFirst" = "$passConfirm" ]
then
clear
echo "Terminal Locked !"
stty intr ''
stty eof ''
stty kill ''
stty stop ''
stty susp ''
echo "To unlock, Enter Password: "
passFirst=""
until [ "$passFirst" = "$passConfirm" ]
do
read -s passFirst
done
stty intr '^C'
stty eof '^D'
stty kill '^U'
stty stop '^S'
stty susp '^Z'
echo "Terminal Unlocked !"
exit
else
echo "Password Mismatch !"
sleep 3
fi
done
19 changes: 19 additions & 0 deletions Sem1/Unix_Programming/script_4a.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash

if [ $# -eq 0 ]
then
echo "This script requires atleast one filename as arguement"
else
for i in $*
do
if [ -f $i ]
then
tr '[a-z]' '[A-Z]' < $i>tempFile
mv tempFile $i
echo "File $i has been translated."
else
echo "$i does not exist in the current directory"
exit 1
fi
done
fi
32 changes: 32 additions & 0 deletions Sem1/Unix_Programming/script_4b.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
clear

if [ $# -eq 0 ]
then
printf "Invalid arguments"
else
if [ $# -eq 1 ]
then
dir=`pwd`
elif [ $# -eq 2 ]
then
dir=$2
fi

if [ -f $1 ]
then
inode=`ls -i $1 | cut -d " " -f 1`
printf "hard link of $1 are:\n"
find $dir -inum $inode
find $dir -type l -ls |tr -s " " |grep $1 |cut -d " " -f 12 > soft
s=`wc -l < soft`
if [ $s -eq 0 ]
then
echo "There is no soft links"
else
echo "Soft links of $1 are"
cat soft
fi
else
printf "file doesn't exist"
fi
fi
11 changes: 11 additions & 0 deletions Sem1/Unix_Programming/script_5a.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

if [ ! -f "$1" ] || [ $# -ne 1 ]
then
echo "This script only accepts one valid filename as arguement!"
else
statLAT=$(stat --printf "%x" $1)
lat=$(date --date="$statLAT" +"%d/%m/%Y %I:%M %p")
echo "FileName: $1"
echo "Last Access Time: $lat"
fi
12 changes: 12 additions & 0 deletions Sem1/Unix_Programming/script_5b.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

echo "Current Date: $(date +"%d/%m/%Y")\n"
currDate=$(date +"%d")
if [ $currDate -le 9 ]
then
currDate=$(echo $currDate | cut -f 2)
echo "$(ncal | sed 's/\b'"$currDate"'\b/'*'/')"
else
echo "$(ncal | sed 's/\b'"$currDate"'\b/'**'/')"
fi

17 changes: 17 additions & 0 deletions Sem1/Unix_Programming/script_6a.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash
if [ $# -eq 0 ]
then
echo “No arguments”
exit
else
list=$(grep -rwlc "$1" *)
if [ $? -eq 0 ]
then
for x in $list
do
echo "Filename: $x"
cat $x
cp -v $x ~/mydir
done
fi
fi
13 changes: 13 additions & 0 deletions Sem1/Unix_Programming/script_6b.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

currentDir=$(pwd)
listOfFiles=$(ls -l "$currentDir" | awk '{print $9}')
echo "Current Directory: $currentDir"
echo "All files whose filename is at least 10 characters: "
for f in $listOfFiles
do
if [ $(expr length "$f") -gt 10 ]
then
echo $f
fi
done
15 changes: 15 additions & 0 deletions Sem1/Unix_Programming/script_7a.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

currentTime=$(date +"%H")
if [ $currentTime -ge 00 ] && [ $currentTime -le 11 ]
then
echo "Good Morning!"
elif [ $currentTime -ge 12 ] && [ $currentTime -le 14 ]
then
echo "Good Afternoon!"
elif [ $currentTime -ge 15 ] && [ $currentTime -le 18 ]
then
echo "Good Evening!"
else
echo "Good Night!"
fi
18 changes: 18 additions & 0 deletions Sem1/Unix_Programming/script_7b.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

if [ $# -lt 2 ]
then
echo "This script takes in two filenames as arguements"
exit
else
string1=`cat $1 | tr '\n' ' '`
for (( i=2; i<=$#; i++ ))
do
echo "Filename: ${!i}"
for a in $string1
do
echo "$a: `grep -c "$a" "${!i}"`"
done
done
fi

Loading