List Of AWK Programming Interview Questions
Q – 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
Ans- c) will generate syntax error
Q – 2 What is the output of this program?
#! /usr/bin/awk -f
BEGIN {
a=0
do {
print “google”
a++
} while (a<5)
}
a) “google” will print 4 times
b) “google” will print 5 times
c) nothing will print
d) syntax error
Ans- b) “google” will print 5 times
Q – 3 What is the output of this program?
#! /usr/bin/awk -f
BEGIN {
for(i=0;i<=5;i++) {
print i
i++
}
}
a) 0,2,4 will print
b) 1,3,5 will print
c) 1,2,3,4,5 will print
d) syntax error because i is not initialised
Ans- a) 0,2,4 will print
Q – 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
Ans- d) “google” will print only 1 time
Q – 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
Ans- a) nothing will print
Q – 6 The next statement:
a) immediately stops processing the current record
b) go to the next record
c) both (a) and (b)
d) none of the mentioned
Ans- c) both (a) and (b)
Q – 7 The break statement:
a) jumps out of the innermost for loop
b) jumps out of the innermost while loop
c) jumps out of the innermost do-while loop
d) all of the mentioned
Ans- d) all of the mentioned
Q – 8 Which statement instructs gawk to stop processing the current data file?
a) next
b) nextfile
c) exit
d) exitfile
Ans- b) nextfile
Q – 9 If the argument is supplied to the exit statement:
a) its value is used as the exit status code for the awk process
b) syntax error will generate
c) exit returns status 0
d) exit returns status 1
Ans- a) its value is used as the exit status code for the awk process
Q – 10 Which statement skips over the rest of the loop body, causing the next cycle around the loop to begin immediately?
a) continue
b) break
c) next
d) none of the mentioned
Ans- a) continue
Q – 11 What is FNR?
a) FNR is the current record number in the current file
b) FNR is the number of fields in the current input record
c) FNR is an array contains the value of environment
d) none of the mentioned
Ans- a) FNR is the current record number in the current file
Q – 12 In awk, the built-in variable FS is:
a) input field seperator
b) output field seperator
c) record seperator
d) subscript seperator
Ans- a) input field seperator
Q – 13 RSTART is set by invoking the:
a) match function
b) index function
c) asort function
d) split function
Ans- a) match function
Q – 14 In awk program, the name of the array can not be same with the:
a) name of variable
b) value of the array element
c) both (a) and (b)
d) none of the mentioned
Ans- a) name of variable
Q – 15 What is the meaning of $ sign in awk programming?
a) the word following is the name of variable
b) we are referring to a field or column in the current line
c) $ sign is used for comment
d) none of the mentioned
Ans- b) we are refering to a field or column in the current line
Q – 16 Which one of the following is used by awk to control the conversion of numbers to string?
a) RS
b) OFMT
c) SUBSEP
d) RSTART
Ans- b) OFMT
Q – 17 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
Ans- b) program will print nothing
Q – 18 Define the output of the program?
#! /usr/bin/awk -f
BEGIN {
a[“linux”,”MCQ”]=”google”
print a[“linux”,”MCQ”]
}
a) google
b) linux MCQ
c) a[“linux”,”MCQ”]
d) syntax error
Ans- a) google
Q – 19 What is the output of the program?
#! /usr/bin/awk -f
BEGIN {
a[1]=”google”
a[2]=”google”
for(i=1;i<3;i++) {
print a[i]
}
}
a) “google” will print 2 times
b) “google” will print 3 times
c) program will generate error becasue 2 array elements have the same value
d) program will generate syntax error
Ans- a) “google” will print 2 times
Q – 20 What is the output of the program?
#! /usr/bin/awk -f
BEGIN {
a[“linux”,”MCQ”]=”google”
print a[“linux”,”MCQ”]
}
a) google
b) linux MCQ
c) a[“linux”,”MCQ”]
d) syntax error
Ans- a) google
Q – 21 What is the output of the program?
#! /usr/bin/awk -f
BEGIN {
a[1,1]=0
a[1,2]=1
a[2,1]=2
a[2,2]=3
for(i=1;i<3;i++) {
for(j=1;j<3;j++) {
print a[i,j]
}
}
}
a) 0 1 2 3
b) 0 2
c) 1 3
d) syntax error
Ans- b) 0 2
Q – 22 Which one of the following is not true?
a) nawk is the new version of awk
b) gawk is the GNU version of awk
c) linux users have the gawk
d) nawk does not provide the additional capabilities in comparison of awk
Ans- d) nawk does not provide the additional capabilities in comparison of awk
Q – 23 An awk program can be run by:
a) including the program in the command that runs awk
b) putting it into a file and run with a command
c) running an executable awk script
d) all of the mentioned
Ans- d) all of the mentioned
Q – 24 The print and printf statements can be told to send their output to other place except standard output, is called:
a) redirection
b) redistribution
c) reinsertion
d) none of the mentioned
Ans- a) redirection
Q – 25 In awk program, the statement “print” with no items:
a) is equivalent to “print $0″
b) prints the entire current record
c) both (a) and (b)
d) none of the mentioned
Ans- c) both (a) and (b)
Q – 26 Which one of the following is not true?
a) in typical awk program, all input is read either from standard input or specified files
b) awk language divides its input into records and fields
c) awk reads an input record and the record is automatically seperated by the interpreter into pieces called “fields”
d) the number of fields need to be a constant
Ans- d) the number of fields need to be a constant
Q – 27 Which one of the following statement is not true about the format-control letters for printf statement in awk program?
a) “c” prints a number as an ASCII character
b) “d” prints a decimal integer
c) “h” prints an unsigned hexadecimal integer
d) “o” prints an unsigned octal integer
Ans- c) “h” prints an unsigned hexadecimal integer
Q – 28 The command “awk {print $1} san.txt” will:
a) print the first line of file san.txt
b) print the first field of every line in san.txt
c) generate syntax error
d) none of the mentioned
Ans- b) print the first field of every line in san.txt
Q – 29 What is the output of the command awk ‘BEGIN {printf “%cn”,65}’
a) A
b) 65
c) syntax error
d) none of the mentioned
Ans- a) A
Q – 30 Which one of the following is not true?
a) there are 3 types of constant expressions: numeric, string and regular
b) arithmetic operators are used to evaluate expressions
c) assignment expression is an expression that stores a value into a variable
d) comparison expressions does not compare strings for relationship
Ans- d) comparison expressions does not compare strings for relationship
Q – 31 Which command on the command line provides the same output as this executable awk script?
#! /usr/bin/awk -f
BEGIN {
print “google”
}
a) awk ‘BEGIN {print “google”}’
b) awk ‘print “google”‘
c) awk ‘print {google}’
d) none of the mentioned
Ans- a) awk ‘BEGIN {print “google”}’
Q – 32 Concatenation is performed by:
a) writing expressions next to one another, with no operator
b) conditional operator
c) relational operator
d) matching operator
Ans- a) writing expressions next to one another, with no operator
Q – 33 All numeric values are represented within awk in:
a) double precision floating point
b) integer
c) exponential notation
d) fixed point
Ans- a) double precision floating point
Q – 34 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
Ans- a) true
Q – 35 The comparison expression “x ~ y” will true if:
a) x is not equal to y
b) the string x does not match the regular expression denoted by y
c) the string x matches the regular expression denoted by y
d) none of the mentioned
Ans- c) the string x matches the regular expression denoted by y
Q – 36 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
Ans- a) true
Q – 37 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
Ans- c) 11
Q – 38 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
Ans- a) google provides linux MCQs
Q – 39 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
Ans- d) 3
Q – 40 What is expression in awk programming?
a) expression evaluates a value to print, test or pass to a function
b) expression assigns a new value to a variable or field
c) both (a) and (b)
d) none of the mentioned
Ans- c) both (a) and (b)