Unix Questions and Answers – Various Operations using Awk Command – 3

This set of Tough Unix Questions and Answers 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

Answer: d
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

Answer: c
Explanation: For running a UNIX command within awk, we’ve to use system function. For example,

BEGIN 
{
      system(“date”)   // prints the system date 
}

advertisement
advertisement

3. sqroot(x) function returns the square root of x.
a) True
b) False
View Answer

Answer: b
Explanation: The sqrt(x) function is used for returning the square root of x.
Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!

4. Which of the following is supported by awk?
a) if
b) while
c) for
d) if, while, for
View Answer

Answer: d
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

Answer: b
Explanation: print statement is not necessary for printing a line. If the selection criteria is specified, the specified line is automatically printed.
advertisement

6. awk uses _____ dimensional arrays.
a) one
b) two
c) multi
d) three
View Answer

Answer: a
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

Answer: a
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.
advertisement

8. Which of the following is a built-in function for awk?
a) length
b) index
c) size
d) length and index
View Answer

Answer: a
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

Answer: d
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

Answer: b
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 tough questions and answers on all areas of Unix, here is complete set of 1000+ Multiple Choice Questions and Answers.

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.