Awk Programming Questions & Answers – Basics

This set of Linux / Unix questions and answers focuses on Basics of Awk Programming.

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
View Answer

Answer: d
Explanation: None.

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
View Answer

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
View Answer

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
View Answer

Answer: b
Explanation: None.
advertisement
advertisement

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
View Answer

Answer: c
Explanation: None.

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
View Answer

Answer: a
Explanation: None.

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
View Answer

Answer: b
Explanation: None.

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
View Answer

Answer: a
Explanation: The ASCII value of A is 65.
advertisement

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
View Answer

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?

advertisement
  1.     #! /usr/bin/awk -f
  2.     BEGIN {
  3.         print "sanfoundry"
  4.     }

a) awk ‘BEGIN {print “sanfoundry”}’
b) awk ‘print “sanfoundry”‘
c) awk ‘print {sanfoundry}’
d) none of the mentioned
View Answer

Answer: a
Explanation: None.

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.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.