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

Lab 5 Awk Commands

Uploaded by

urvishabhoi90
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Lab 5 Awk Commands

Uploaded by

urvishabhoi90
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

Lab 05- Scripting with AWK

Name: Urvisha Bhoi


Student ID: 10310981
Course: COMP 75
Section: 01
Due Date: Feb 22nd, 2024
Instructor’s Name: Prof. Melo

Page 1 of 9
Introduction:
AWK is considered to be very important programming language for Linux necessary to learn. AWK
commands replace Linux filter “sed” as it is quite tough to use. So instead of “sed” Linux Filter, its quite
better and easy to use awk command. There are innumerable things to learn about awk scripting such
that the structure how to use awk command statement, BEGIN and END block purpose and how to make
awk scripting file and execute it.

Discussion:

SS1

Page 2 of 9
SS2

Page 3 of 9
SS3

SS4

Page 4 of 9
SS5

Page 5 of 9
SS6

SS7

Page 6 of 9
SS8

Page 7 of 9
Page 8 of 9
Q1) In this awk line (awk ‘ ’ Lab5Part1.dat), no any action such as printing of any line, column, or doing
any calculation between any columns and any specific pattern to display the required output are
mentioned, so by default awk simply processes each line from Lab5Part1.dat without any modifications
in line as no pattern is provided with awk statement and no any action such as printing of line or
calculations occur as no task (action) is provided here.

Q2) The command “awk ‘$5 < 25 {print $1}’ Lab5Part1.dat” has pattern and action both. It has pattern in
which each line’s 5th column data value of the file Lab5Part1.dat is compared with 25 using relational
operator “<”, so first thing an interpreter will encounter is this pattern ($5 < 25) that to execute further
awk statement it should be necessary that the data value of 5th column of a line should be less than 25.
Here the file Lab5Part1.dat contains the final marks of students in 5 th column, so the action is to print
student’s names having final marks less than 25, hence in this command the final marks of students will
be compared to 25 (Final marks should be less than 25 to further execute awk statement) and from the
first column of a file Lab5Part1.dat which contains the student’s names, those student’s names will be
printed which will have their final marks less than 25.

In conclusion, in this way awk statement will work and print the names of students having their final
exams marks less than 25 (Basically Names of students who failed final exams as criteria for passing final
exams is to have marks greater than or equal to 25), same output as sed command used in previous
assignment to print failed student’s names (those students who gained final exams marks less than 25).

Conclusion:
I have learnt how to make a awk script, how to execute it, BEGIN and END Block purpose and the
structure of awk command.

References:

No Reference

Page 9 of 9

You might also like