1) There are the following statements that are given below, which of them are correct about AWK in the Linux operating system?
- AWK is a scripting language, which is used to perform operations on data and generate reports.
- The compilation is not required for AWK programs.
- The compilation is required for AWK programs.
- We can use logical operators, string functions, and numeric functions in AWK programs.
Options:
- A and B
- A and D
- A, B, and D
- A, C, and D
Correct answer: 3
A, B, and D
Statements A, B, and D are correct about AWK in the Linux operating system.
2) What is the full form of AWK?
- Active Working Kit
- Active Well Kudos
- Aho Weinberger Kernighan
- Anderson Washington Kernighan
Correct answer: 3
Aho Weinberger Kernighan
The AWK stands for Aho Weinberger Kernighan. The Aho, Weinberger, and Kernighan are the AWK developers.
3) Which of the following correct tasks that can be done by AWK?
- We can scan a file line by line using AWK.
- It is used to transform data files.
- It is used to perform operations on matched lines.
- We can produce formatted reports using AWK.
Options:
- A and B
- A, C, and D
- A, B, and D
- A, B, C, and D
Correct answer: 4
A, B, C, and D
All given statements are correct about AWK.
4) Suppose that a text file "abc.txt" that contains multiple lines, some of the line contains word "school". Then how to print only those line who contains "school" using AWK?
- awk '/school/ {print}' abc.txt
- awk -check '/school/ {print}' abc.txt
- awk -check '/school/ ' abc.txt
- None of the above
Correct answer: 1
awk '/school/ {print}' abc.txt
The 1st command is correct to print only those lines that contain "school" using AWK.
5) Which of the following are the inbuilt variables in AWK?
- FS
- OFS
- KFS
- ORS
Options:
- A and B
- A, C, and D
- A, B, and D
- A, B, C, and D
Correct answer: 3
A, B, and D
Options A, B, and D are the correct inbuilt variable in AWK.
6) Which of the following is not the inbuilt variable in AWK?
- NR
- NF
- FN
- FILENAME
Correct answer: 3
FN
The "FN" is not a valid inbuilt variable in AWK.
7) Suppose that a text file "abc.txt" that contains multiple lines, then how to print all complete lines with line numbers using AWK?
- awk '{print NS,$1}' abc.txt
- awk '{print NR,$0}' abc.txt
- awk '{print NR,$1}' abc.txt
- awk '{print NS,$1}' abc.txt
Correct answer: 2
awk '{print NR,$0}' abc.txt
The 2nd command is correct to print all complete lines with line numbers using AWK.
8) How to print lines of a given text file from line number 2 to 4 using AWK?
- awk 'NR==2, NR==4 {print NR,$0}' <filename>
- awk 'NR==2 to NR==4 {print NR,$0}' <filename>
- awk 'NR==2-4 {print NR,$0}' <filename>
- awk 'NR==2,4 {print NR,$0}' <filename>
Correct answer: 1
awk 'NR==2, NR==4 {print NR,$0}' <filename>
The 1st command is correct to print lines from 2 to 4.
9) How to print non-empty line from the given file using AWK?
- awk 'NF > 0' <filename>
- awk 'NF' <filename>
- awk 'NE > 0' <filename>
- awk 'NE' <filename>
Correct answer: 1
awk 'NF > 0' <filename>
The 1st command is used to print non-empty line. Because the NF variable denotes number of fields in the file.
10) Which of the following command is used to print the number of lines that exist in the specified file?
- awk 'END { print NL }' <filename>
- awk 'END { print N }' <filename>
- awk 'END { print NR }' <filename>
- awk 'END { print NN }' <filename>
Correct answer: 3
awk 'END { print NR }' <filename>
The 3rd option is correct, because -12 describes, it do not display 1st and 2nd column.
11) Which of the following command is used to print the 3rd column of a specified file?
- awk '{print $3} <filename>
- awk '{print $2} <filename>
- awk '{print $N2} <filename>
- awk '{print $N3} <filename>
Correct answer: 2
awk '{print $2} <filename>
12) What is the full form of OFS in AWK?
- Object Field Separator
- Obsolete Field Separator
- Officiated Field Separator
- Output Field Separator
Correct answer: 4
Output Field Separator
The "OFS" stands for "Output Field Separator".
13) Which of the following is known as match operator in AWK?
- =
- !
- ~
- ==
Correct answer: 3
~
The tilde is known as a match operator in AWK.
14) Which of the following built-in variable is used that contains the name of the specified file in the AWK command?
- NAME
- FILENAME
- FNAME
- FN
Correct answer: 2
FILENAME
The FILENAME variable contains the name of the specified file in the AWK command.
15) What is the full form of ORS in AWK?
- Output Record Separator
- Output Record Symbol
- Output Resumed Symbol
- Object Record Separator
Correct answer: 1
Output Record Separator
The "ORS" stands for "Output Record Separator".