1. In awk, the built-in variable FS is
a) input field seperator
b) output field seperator
c) record seperator
d) subscript seperator
View Answer
Explanation: None.
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
View Answer
Explanation: None.
3. RSTART is set by invoking the
a) match function
b) index function
c) asort function
d) split function
View Answer
Explanation: None.
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
View Answer
Explanation: None.
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
View Answer
Explanation: None.
6. 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
View Answer
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/sanfoundry# ./test.awk
root@ubuntu:/home/sanfoundry#
7. What is the output of the program?
#! /usr/bin/awk -f
BEGIN {
a[1]="sanfoundry"
a[2]="sanfoundry"
for(i=1;i<3;i++) {
print a[i]
}
}
a) “sanfoundry” will print 2 times
b) “sanfoundry” will print 3 times
c) program will generate error becasue 2 array elements have the same value
d) program will generate syntax error
View Answer
Explanation: None.
Output:
root@ubuntu:/home/sanfoundry# ./test.awk
sanfoundry
sanfoundry
root@ubuntu:/home/sanfoundry#
8. What is the output of the program?
#! /usr/bin/awk -f
BEGIN {
a[1]="sanfoundry"
delete a[1]
print a[1]
}
a) program will print “sanfoundry”
b) program will print nothing
c) program will generate syntax error
d) program will generate fatal error
View Answer
Explanation: The delete command deletes the array element.
Output:root@ubuntu:/home/sanfoundry# ./test.awk
root@ubuntu:/home/sanfoundry#
9. What is the output of the program?
#! /usr/bin/awk -f
BEGIN {
a["linux","MCQ"]="sanfoundry"
print a["linux","MCQ"]
}
a) sanfoundry
b) linux MCQ
c) a[“linux”,”MCQ”].
d) syntax error
View Answer
Explanation: None.
Output:
root@ubuntu:/home/sanfoundry# ./test.awk
sanfoundry
root@ubuntu:/home/sanfoundry#
10. 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
View Answer
Explanation: None.
Output:
root@ubuntu:/home/sanfoundry# ./test.awk
0
2
root@ubuntu:/home/sanfoundry#
Sanfoundry Global Education & Learning Series – Linux Administration & Programming.
Here’s the list of Best Books in Linux Commands & Shell Programming.
Here’s the list of Best Books in Linux Kernel, Device-Drivers & System Programming.
To practice all questions on Linux Administration & Programming, here is complete set of 1000+ Multiple Choice Questions and Answers on Linux.
- Apply for Linux Internship
- Buy Linux Books
- Apply for Programming Internship
- Buy Information Technology Books
- Practice Programming MCQs