Awk Programming Questions & Answers on Variables & Array for Freshers
https://www.computersprofessor.com/2018/07/awk-programming-questions-answers-on_31.html
1. In awk, the built-in variable FS is
a) input field seperator
b) output field seperator
c) record seperator
d) subscript seperator
Answer: a
2. 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
Answer: a
3. RSTART is set by invoking the
a) match function
b) index function
c) asort function
d) split function
Answer: a
4. 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
Answer: b
5. 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) name of variable & value of the array element
d) none of the mentioned
Answer: a
6. What is the output of the program?
#! /usr/bin/awk -f#This filename is text.awkBEGIN {
print FILENAME
}
a) test.awk
b) program will print nothing
c) syntax error
d) fatal error
b) program will print nothing
c) syntax error
d) fatal error
Answer: b
7. What is the output of the program?
#! /usr/bin/awk -fBEGIN {
a[1]="computersprofessor"
a[2]="computersprofessor"
for(i=1;i<3;i++) {
print a[i]
}}
a) “computersprofessor” will print 2 times
b) “computersprofessor” will print 3 times
c) program will generate error becasue 2 array elements have the same value
d) program will generate syntax error
b) “computersprofessor” will print 3 times
c) program will generate error becasue 2 array elements have the same value
d) program will generate syntax error
Answer: a
8. What is the output of the program?
#! /usr/bin/awk -fBEGIN {
a[1]="computersprofessor"
delete a[1]
print a[1]
}
a) program will print “computersprofessor”
b) program will print nothing
c) program will generate syntax error
d) program will generate fatal error
b) program will print nothing
c) program will generate syntax error
d) program will generate fatal error
Answer: b
9. What is the output of the program?
#! /usr/bin/awk -fBEGIN {
a["linux","MCQ"]="computersprofessor"
print a["linux","MCQ"]
}
a) computersprofessor
b) linux MCQ
c) a[“linux”,”MCQ”].
d) syntax error
b) linux MCQ
c) a[“linux”,”MCQ”].
d) syntax error
Answer: a
10. What is the output of the program?
#! /usr/bin/awk -fBEGIN {
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
b) 0 2
c) 1 3
d) syntax error
Answer: b






























