This set of Unix Multiple Choice Questions & Answers (MCQs) focuses on “Various Operations using Awk Command – 2”.
1. ____ section can be used if we’ve to print something before processing the first line.
a) end
b) begin
c) start
d) first
View Answer
Explanation: awk statements are usually applied to all the lines selected by the address. But if we want to print something before processing the first line, for example, a heading, then the BEGIN section can be used. The syntax is:
BEGIN { action }
2. ____ section can be used if we’ve to print something after processing the last line.
a) end
b) begin
c) start
d) first
View Answer
Explanation: awk statements are usually applied to all the lines selected by the address. But if we want to print something after processing the first line, for example, a footer, then the END section can be used. The syntax is:
END { action }
3. awk uses ____ for providing comments.
a) %%
b) //
c) #
d) $$
View Answer
Explanation: Like shell, awk also used the # symbol for providing comments. For example,
BEGIN { printf “\t\t employee data\n\n” } # demonstration of BEGIN section - (this is a comment line)
4. Which of the following is a built-in variable for awk?
a) ps
b) $0
c) FS
d) FN
View Answer
Explanation: awk has several built-in variables like FS, OFS, NF each of which serves a different purpose.
5. FS defines the field separator.
a) True
b) False
View Answer
Explanation: As we know that, awk uses a contiguous set of space as the default field delimiter. FS defines this field separator. For example,
BEGIN { FS= “|” } // | is the delimiter now
6. Which built variable is used for defining the field delimiter in the output?
a) OFS
b) FS
c) NF
d) ES
View Answer
Explanation: The OFS variable is used for specifying the field delimiter in the output. For example,
BEGIN { OFS= “~” } // output fields will be separated with a tidle.
7. The ____ variable stores the name of the file currently being processed.
a) OFS
b) FILENAME
c) NF
d) ES
View Answer
Explanation: awk supports another built-in variable named FILENAME which stores the name of the file, currently being processed.
8. Which of the following is not a built-in variable used by awk?
a) ES
b) FILENAME
c) argv
d) argc
View Answer
Explanation: argv is used for storing the list of arguments while argc stores the number of arguments in the command line.
9. awk supports the use of arrays.
a) True
b) False
View Answer
Explanation: awk supports the use of arrays but awk arrays differ from those arrays used in another programming language. These arrays are accessed normally using an index.
10. Which of the following is not true about awk arrays?
a) they are not expanded automatically
b) they are initialized to zero or an empty string
c) index can be a string also
d) they are not formally defined
View Answer
Explanation: awk supports the use of arrays but awk arrays differ from those arrays used in another programming language. awk arrays are expanded automatically.
11. Which of the following is an associative array?
a) a[ ]
b) arr[ ]
c) envr [ ]
d) ENVIRON[ ]
View Answer
Explanation: awk doesn’t treat array indices as integers. Awk arrays are associative (hash) arrays. Similarly, ENVIRON[ ] is also an associative array, known as environment array which is used to store all environment variables.
Sanfoundry Global Education & Learning Series – Unix.
To practice all areas of Unix, here is complete set of 1000+ Multiple Choice Questions and Answers.
- Check MCA Books
- Check Computer Science Books
- Check Unix Books
- Practice MCA MCQs
- Practice Computer Science MCQs