Awk Programming Interview Preparation Guide
Download PDF

Awk Programming frequently Asked Questions in various Awk Programming job Interviews by interviewer. The set of questions here ensures that you offer a perfect answer posed to you. So get preparation for your new job hunting

40 Awk Programming Questions and Answers:

Table of Contents

Awk Programming Interview Questions and Answers
Awk Programming Interview Questions and Answers

2 :: What is the output of this program?

#! /usr/bin/awk -f
BEGIN {
two=2;
two++;
print two
}
a) two
b) three
c) 2
d) 3

d) 3
Output:
root@ubuntu:/home/google# chmod +x test.awk
root@ubuntu:/home/google# ./test.awk
3
root@ubuntu:/home/google#

3 :: What is the output of this program?

#! /usr/bin/awk -f
BEGIN {
var1="google"
var2="linux"
print var1" provides "var2" MCQs "
}
a) google provides linux MCQs
b) var1 provides var2 MCQs
c) provides MCQs
d) syntax error

a) google provides linux MCQs
Output:
root@ubuntu:/home/google# chmod +x test.awk
root@ubuntu:/home/google# ./test.awk
google provides linux MCQs
root@ubuntu:/home/google#

4 :: What is the output of this program?

#! /usr/bin/awk -f
BEGIN {
one=10;
two=3;
print (one%two)+10
}
a) (one%two)+10
b) 13
c) 11
d) syntax error

c) 11
Explanation:
The remainder of 10/3 is 1. remainder is added to 10.
Output:
root@ubuntu:/home/google# chmod +x test.awk
root@ubuntu:/home/google# ./test.awk
11
root@ubuntu:/home/google#

5 :: What is the output of this program?

#! /usr/bin/awk -f
BEGIN {
a=10;
b=10;
print a==b ? "true":"false"
}
a) true
b) false
c) syntax error
d) none of the mentioned

a) true
Output:
root@ubuntu:/home/google# chmod +x test.awk
root@ubuntu:/home/google# ./test.awk
true
root@ubuntu:/home/google#

7 :: What is the output of this program?

#! /usr/bin/awk -f
BEGIN {
print "20"<"9" ? "true":"false"
}
a) true
b) false
c) syntax error
d) none of the mentioned

a) true
Explanation:
The operands of relational operators are converted to, and compared as string if both are not numbers. Strings are compared by comparing the characters of each. Hence 20 is less then 9.
Output:
root@ubuntu:/home/google# chmod +x test.awk
root@ubuntu:/home/google# ./test.awk
true
root@ubuntu:/home/google#

9 :: Concatenation is performed by:
a) writing expressions next to one another, with no operator
b) conditional operator
c) relational operator
d) matching operator

a) writing expressions next to one another, with no operator

24 :: What is the output of the program?

#! /usr/bin/awk -f
#This filename is text.awk
BEGIN {
print FILENAME
}
a) test.awk
b) program will print nothing
c) syntax error
d) fatal error

b) program will print nothing
Explanation:
The built-in variable FILENAME is the name of file that awk is currently reading and in this program there is no file listed on the command line.
Output:
root@ubuntu:/home/google# ./test.awk
root@ubuntu:/home/google#