0% found this document useful (0 votes)
57 views3 pages

LAB 2 and 3 Operating Systems by Muhammad Qubais Hafeez

The document discusses 4 tasks related to operating systems. The first task uses a for loop to echo file names with a .txt extension. The second task uses a bash script to build a basic calculator that takes user input for two numbers and an operation and displays the result. The third task demonstrates counting the number of lines and words in a file using awk commands.

Uploaded by

Muhammad Qubais
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)
57 views3 pages

LAB 2 and 3 Operating Systems by Muhammad Qubais Hafeez

The document discusses 4 tasks related to operating systems. The first task uses a for loop to echo file names with a .txt extension. The second task uses a bash script to build a basic calculator that takes user input for two numbers and an operation and displays the result. The third task demonstrates counting the number of lines and words in a file using awk commands.

Uploaded by

Muhammad Qubais
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/ 3

LAB 2 and 3

Operating Systems

By Muhammad Qubais Hafeez

Task#1:

yourfilenames=`ls ./*.txt`
for eachfile in $yourfilenames
do
echo $eachfile
done

Task#2:

# !/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"
Task#3:
file_path="/home/qubais/Desktop/demo.txt"

echo "Using method 1"


# using awk command to count number of lines
awk 'BEGIN{c1=0} //{c1++} END{print "Number of lines: ",c1}' $file_path

#using awk command to count number of words


awk 'BEGIN{c=0} //{c++} END{print "Number of words: ",c}' RS="[[:space:]]" $file_path

Task#4:
File output:

You might also like