Yuktha-Unix Final Report
Yuktha-Unix Final Report
COLLEGE OF ENGINEERING
(Autonomous College under VTU, Approved by AICTE, Accredited by NAAC)
MASTER OF COMPUTER APPLICATIONS
(Accredited by NBA for 5 years 2019 - 2024)
LAB RECORD
SUBMITTED BY
Tejaswini N (1BM23MC103)
S Shilpa
(Assistant Professor)
B.M.S. COLLEGE OF ENGINEERING
(Autonomous College under VTU, Approved by AICTE, Accredited by NAAC)
MASTER OF COMPUTER APPLICATIONS
(Accredited by NBA for 5 years 2019 - 2024)
LABORATORY CERTIFICATE
Examiner:
1.
2.
Table of Contents
Content Pa
ge
N
o.
Lab-1
1. Display the calendar of the year 2023.
2. Display the current date in “dd/mm/yy” format.
3. Display time as hh:mm
4. Display the following with a single echo command:
*********
Unix Lab
*********
5. Display terminal name and login name
Lab-2
1. Display all the properties of regular files in current directory
2. Create two regular files and concatenate both the files.
3. Rename a file and copy the contents of one file to the other file.
4. Create a directory and delete a directory
Lab-3
1. Display octal equivalent for every character along with characters in the file
2. Convert the upper case characters in a file to lower case.
3. Display contents of file after squeezing the multiple blank lines into a single blank
line.
4. Display with message no.of lines,Words and characters in a file.
Lab-4
1. Create two files and display the common lines between those two files.
2. Sort the contents of the file in descending order.
3. Display the first line and last line of the file.
4. Display the lines from 4 to 6 of a file
Lab-5
1. Create a file student with entries for (USN, Name, C1_marks, C2_marks, C3_marks,
C4_marks) in each row.
2. Display for all the students, the USN, C2_marks, C4_marks
3. Join two student files vertically
4. Split the file student into different files containing 4 lines each.
5. Display the students whose name starts with a or b.
6. Display the students whose last name is either Gupta or Kumar.
7. Display the students who are born after the year 2000 or afterwards.
Lab-6 Write Shell scripts for the following:
1. Read 3 numbers from the user and find the largest and smallest.
2. Read a string and check if it is empty. Display message appropriately.
3. Read a filename as input from command line and check the type of the file it is
(regular,
qqqdirectory, device, link).
4. Find the simple interest.
Lab-7
1. Write a shell script to read a file name from command line and delete
all the blank lines in the file display all the contents of the file.
2. Write a shell script to read a file name, search pattern, replace pattern
from command line and execute accordingly.
3. Read a file name from the command line as absolute path name and check if it has
execute permission for all 3 types of users.
4. Read the user choice and compute basic arithmetic operations based on the choice.
Lab-8
1. Create a file of employee in the following format use awk programming to display
contents of the input file.
Emp-id|Name|DOB|Job|Department|Salary
2. Display the employee details who works for either Administration or Sales
department.
3. Display the employee who earn between 1-2 lakhs.
4. Display the employee who are born after 20th century.
5. Display the names of employees and their department whose names start with S or A
6. Find the total no. of employees of the company.
Lab-9:
1. Write a awk script to read cie marks and see marks of a student is a particular course
and rrrrfind out the total marks and grade he or she has got.
2. Write an awk program to find total number of employees exists for each designation.
Lab-10
1. Write an awk script to calculate the HRA, DA and the gross salary of
an employee. If the basic is less than 6000/- then HRA is 50% of the basic, DA is 25%
yyyof the basic otherwise the HRA is 40% and DA is 1000/-
22MCA1PCUS: Unix & Shell Programming
Lab-1
Output:
Output:
Output:
Output:
Output:
Output:
Output:
Lab-3
1. Display octal equivalent for every character along with characters in
the file
Code:
$ od -bc f2.txt
Output:
Output:
3. Display contents of file after squeezing the multiple blank lines into a single blank line.
Code:
$ tr -s '\n' < f4.txt
Output:
Output:
1. Create two files and display the common lines between those two files.
Code:
$ grep -Fx -f l4c4 l4c3
Output:
Output:
Output:
Output:
Lab-5
1. Create a file student with entries for (USN, Name, C1_marks, C2_marks,
C3_marks, C4_marks) in each row.
Code:
$ gedit student.txt
USN |Name |C1_Marks |C2_Marks |C3_Marks |C4_Marks
B0101|Julie |60 |70 |75 |80
B0102|Abhi |90 |100 |98 |90
B0103|Bhumi |96 |87 |93 |90
B0104|Bhanu |79 |76 |94 |88
B0105|Arun |80 |95 |98 |90
B0106|Sindhu |60 |50 |56 |77
B0107|Tanu |90 |70 |86 |68
B0108|Kavya |59 |80 |76 |77
B0109|Jenny |89 |70 |89 |88
B0110|Ashwith |78 |85 |99 |96
Output:
4. Split the file student into different files containing 4 lines each.
Code:
$ split -l 4 student.txt stud-
Output:
Output:
Output:
7. Display the students who are born after the year 2000 or afterwards.
Code:
echo "All the students whose are born in the year 2000 or afterwards:"
grep "[0-9][0-9]/[0-9][0-9]/200[0-9]" stud1.sh
Output:
1. Read 3 numbers from the user and find the largest and smallest.
Code:
echo "Enter 3 numbers seperated by space:"
read a b c
#to find largest number among 3
if [ $a -ge $b ] && [ $a -ge $c ]
then
echo "$a is the largest number"
elif [ $b -ge $a ] && [ $b -ge $c ]
then
echo "$b is the largest number"
else
echo "$c is the largest number"
fi
3. Read a filename as input from command line and check the type of the file it is (regular,
directory, device, link).
Code:
#creating a linkfile
#ln -s sourceFile targetFile
elif [ -c $1 ]; then
echo "$1 is a character device file"
else
echo "$1 is of an unknown type"
fi
else
echo "$1 does not exist"
fi
Output:
Lab-7
1. Write a shell script to read a file name from command line and delete
all the blank lines in the file display all the contents of the file.
Code:
# Check if a file name is provided using $#
if [ $# -eq 0 ]; then
echo "Please provide the file name in command line"
exit 1
fi
else
echo "$1 does not exist"
fi
Output:
2. Write a shell script to read a file name, search pattern, replace pattern
from command line and execute accordingly.
Code:
# Read the file name, search pattern, and replace pattern from the command line
file=$1
search_pattern=$2
replace_pattern=$3
# Use sed to replace the search pattern with the replace pattern in the file
#example: sed "s/hello/hi/g" file to replace all occurrences of "hello" with "hi"
#Here's what each part does:
Output:
3. Read a file name from the command line as absolute path name and check if it has execute
permission for all 3 types of users.
Code:
# Check if file name is provided in command line or not using $#
if [ $# -eq 0 ]; then
echo "Please provide the file name in command line"
exit 1
fi
# Read the file name from the command line and name it as file1
file1=$1
Output:
4. Read the user choice and compute basic arithmetic operations based on the choice.
Code:
while true; do
echo "Choose an arithmetic operation:"
echo "1. Addition"
echo "2. Subtraction"
echo "3. Multiplication"
echo "4. Division"
echo "5. Exit"
case $choice in
1)
read -p "Enter the first number: " num1
read -p "Enter the second number: " num2
result=$((num1 + num2))
echo "Result: $result"
;;
2)
read -p "Enter the first number: " num1
read -p "Enter the second number: " num2
result=$((num1 - num2))
echo "Result: $result"
;;
3)
read -p "Enter the first number: " num1
read -p "Enter the second number: " num2
result=$((num1 * num2))
echo "Result: $result"
;;
4)
read -p "Enter the first number: " num1
read -p "Enter the second number: " num2
result=$(echo "scale=2; $num1 / $num2" | bc)
echo "Result: $result"
;;
5)
echo "Exiting..."
exit 0
;;
*)
echo "Invalid choice! Please choose a valid option."
;;
esac
done
Output:
Lab-8
Output:
2. Display the employee details who works for either Administration or Sales
department.
Code:
$awk -F'|' '$4 ~ /administration|sales/ {print}' emp.txt
Output:
Output:
5. Display the names of employees and their department whose names start with S or A
Code:
awk -F "|" '$2 ~ /^[SA]/ {print $2, "|", $4}' emp.txt
Output:
Lab-9:
1. Write a awk script to read cie marks and see marks of a student is a particular course and find
out the total marks and grade he or she has got.
Code:
awk -F "|" '{total = ($3 + $4)/2; print $0, "Total Marks:", total, "Grade:", (total >= 90 ? "A" : total >= 75 ?
"B" : "C")}' student.txt
Output:
2. Write an awk program to find total number of employees exists for jj nn each designation.
Code:
awk -F "|" '{ count[$3]++ } END { for (desig in count) print desig, ":", count[desig], "employees" }'
emp.txt
Output:
Lab-10
1. Write an awk script to calculate the HRA, DA and the gross salary of
an employee. If the basic is less than 6000/- then HRA is 50% of the basic, DA is 25% of the basic
otherwise the HRA is 40% and DA is 1000/-
Code:
awk -F'|' '{if ($6 < 6000) {HRA=$6*0.5; DA=$6*0.25} else {HRA=$6*0.4; DA=1000};
Gross=$6+HRA+DA; print $0, "HRA:", HRA, "DA:", DA, "Gross:", Gross}' emp.txt
Output: