Awk Programming Questions & Answers on Basics for Freshers

https://www.computersprofessor.com/2018/07/awk-programming-questions-answers-on.html
1. 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
Answer: d
2. 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
Answer: d
Explanation: The method used to run awk program depends on the program size and input files.
3. 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
Answer: d
Explanation: The number of fields does not need to be a constant.
4. What is the meaning of $ sign in awk programming?
a) the word following is the name of variable
b) we are refering to a field or column in the current line
c) $ sign is used for comment
d) none of the mentioned
Answer: b
5. In awk program, the statement “print” with no items
a) is equivalent to “print $0”
b) prints the entire current record
c) is equivalent to “print $0” & prints the entire current record
d) none of the mentioned
Answer: c
6. 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
Answer: a
7. 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
Answer: b
8. What is the output of the command awk ‘BEGIN {printf “%c\n”,65}’
a) A
b) 65
c) syntax error
d) none of the mentioned
Answer: a
Explanation: The ASCII value of A is 65.
9. 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
Answer: c
Explanation: “x” prints and unsigned hexadecimal integer
10. Which command on the command line provides the same output as this executable awk script?
#! /usr/bin/awk -f
BEGIN {
print "sanfoundry"
}
a) awk ‘BEGIN {print “sanfoundry”}’
b) awk ‘print “sanfoundry”‘
c) awk ‘print {sanfoundry}’
d) none of the mentioned
b) awk ‘print “sanfoundry”‘
c) awk ‘print {sanfoundry}’
d) none of the mentioned
Answer: a