Interviewer And Interviewee Guide

Fresh Awk Programming Interview Questions & Answers:

1. The command "awk '{if ("9″>"10″) print "google" else print "linux"}'"
a) will print "google"
b) will print "linux"
c) will generate syntax error
d) none of the mentioned

c) will generate syntax error
Explanation:
Semicolon is required just before the else statement to parse the statement.
Output:
root@ubuntu:/home/google# awk '{if ("9″>"10″) print "google" else print "linux"}'
awk: {if ("9″>"10″) print "google" else print "linux"}
awk: ^ syntax error
root@ubuntu:/home/google#

4. What is the output of this program?

#! /usr/bin/awk -f
BEGIN {
a=6
do {
print "google"
a++
} while (a<5)
}
a) nothing will print
b) "google" will print 5 times
c) "google" will print 4 times
d) "google" will print only 1 time

d) "google" will print only 1 time
Explanation:
Even the condition is false of do-while loop, the body is executed once.
Output:
root@ubuntu:/home/google# ./test.awk
google
root@ubuntu:/home/google#

5. What is the output of this program?

#! /usr/bin/awk -f
BEGIN {
a=5
while (a<5) {
print "google"
a++;
}
}
a) nothing will print
b) "google" will print 5 times
c) program will generate syntax error
d) none of the mentioned

a) nothing will print
Explanation:
The condition of while statement is false so commands inside the loop will not execute.
Output:
root@ubuntu:/home/google# ./test.awk
root@ubuntu:/home/google#

Copyright 2007-2024 by Interview Questions Answers .ORG All Rights Reserved.
https://InterviewQuestionsAnswers.ORG.