This set of Unix Multiple Choice Questions & Answers (MCQs) focuses on “Various Operations using Awk Command – 3”.
1. ____ function breaks up a string on the basis of delimiter.
a) length
b) substr
c) system
d) split
View Answer
Explanation: The split function breaks a substr str on the basis of delimiter. The syntax is split (stg, arr, ch) where stg is the string to be broken, ch is delimeter and arr is the array which stores the fields.
2. For running a UNIX command within awk, we’ve to use ____ function.
a) length
b) substr
c) system
d) split
View Answer
Explanation: For running a UNIX command within awk, we’ve to use system function. For example,
BEGIN { system(“date”) // prints the system date }
3. sqroot(x) function returns the square root of x.
a) True
b) False
View Answer
Explanation: The sqrt(x) function is used for returning the square root of x.
4. Which of the following is supported by awk?
a) if
b) while
c) for
d) if, while, for
View Answer
Explanation: awk generally supports all the functions and features of a modern programming language. It provides if condition for control flow and while, for loop for repeatedly executing the instructions.
5. print statement is necessary for printing a line.
a) True
b) False
View Answer
Explanation: print statement is not necessary for printing a line. If the selection criteria is specified, the specified line is automatically printed.
6. awk uses _____ dimensional arrays.
a) one
b) two
c) multi
d) three
View Answer
Explanation: awk supports one-dimensional arrays where the array subscript can be a string also.
7. awk has some built-in functions which are used for arithmetic and string operations.
a) True
b) False
View Answer
Explanation: awk also has several built-in functions which are used for performing arithmetic as well as string operations. The arguments to these functions are passed in C style.
8. Which of the following is a built-in function for awk?
a) length
b) index
c) size
d) length and index
View Answer
Explanation: awk has several built-in functions which are used for performing arithmetic as well as string operations. The length function is used for determining the length of its argument while the index is used for determining the position of a string str1 within another string str2.
9. The _____ function extracts a substring from a string.
a) length
b) index
c) size
d) substr
View Answer
Explanation: The substr function is used for extracting a substring from a string. The syntax for using this function is substr (str,m,n) where str is the string from which extraction is done. m represents the starting point of extraction and n indicates the number of characters to be extracted.
10. awk makes a distinction between numeric and string variables.
a) True
b) False
View Answer
Explanation: awk has no procedure for a distinction between numeric and string variables. It can perform numeric computations for a string as well.
Sanfoundry Global Education & Learning Series – Unix.
To practice all areas of Unix, here is complete set of 1000+ Multiple Choice Questions and Answers.
- Check Computer Science Books
- Check Unix Books
- Apply for Computer Science Internship
- Check MCA Books
- Practice MCA MCQs