Automata Theory Questions and Answers – Regular Expression in UNIX

«
»

This set of Automata Theory Multiple Choice Questions & Answers (MCQs) focuses on “Regular Expression in UNIX”.

1. Which among the following is not a UNIX command for regular expressions?
a) ed
b) sed
c) vi
d) none of the mentioned
View Answer

Answer: d
Explanation: Regular expressions are used by different commands in Unix like ed, sed, grep, awk, vi, etc. Sed stands for stream editor which is exclusively used for executing scripts.
advertisement

2. What is the significance of $ used in regular expression in UNIX?
a) Matches the beginning of the line
b) Matches the end of lines
c) Matches any single character
d) None of the mentioned
View Answer

Answer: b
Explanation: Regular expression provides more flexibility while matching string patterns. Special characters like ^, $, *, . are very useful.

3. Generate the regular expression to match blank lines
a) / */
b) /bl
c) /^?/
d) /^$/
View Answer

Answer: d
Explanation: There are few expressions which provide the utility of matching metacharacters including /^$/ for blank lines, / */ for matching one or more spaces, /^.*$/ for matching an entire line whatever it is.
Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!
advertisement
advertisement

4. For the given syntax of sed, which among the following is not a correct option?
General syntax of sed: /pattern/action
a) / are used as delimiters
b) pattern refers to a regular expression
c) pattern refers to the string to be matched
d) action refers to the command
View Answer

Answer: c
Explanation: In the general syntax of sed, pattern is the regular expression and action refers to the command given (p: prints the line, d: deletes the line, etc).

5. What does grep do in UNIX?
a) It is an editor in UNIX
b) It searches for text patterns
c) It is an editor in UNIX and it searches for text patterns
d) None of the mentioned
View Answer

Answer: b
Explanation: The grep is a standard UNIX utility program that searches through a set of files in search of a text pattern,specified through a regular expression.
advertisement

6. State true or false:
Statement: A regular expression is a sequence of characters that represent a pattern.
a) true
b) false
View Answer

Answer: a
Explanation: Such a generated pattern could be a fixed word or describe something like more general.

7. Which of the following options support the given statement?
Statement: A regular expression could be a fixed word or describe something like more general.
a) This flexibility makes Regular expression invaluable
b) This flexibility makes the Regular expression unvaluable
c) This flexibility makes Regular expression invaluable and unvaluable
d) None of the mentioned
View Answer

Answer: a
Explanation: Regular expressions are very much invaluable tools; they can be used to find a particular segment of line in a file and instruct to take certain actions.
advertisement

8. What does the following segment of code does?
grep -i man heroes.txt
a) manually opens a file called heroes.txt
b) manages heroes.txt
c) search for “man” in the file “heroes.txt”
d) none of the mentioned
View Answer

Answer: c
Explanation: grep is a command which finds the pattern in a particular text segment.Here, it scans each line in heroes.txt and looks for an m followed by a and then followed by n.

9. What does “X?” do regular expression operator?
a) Matches zero or more capital X’s
b) Matches no or one occurence of the capital letter X
c) Matches one or more capital X’s
d) All of the mentioned
View Answer

Answer: b
Explanation: There are many other common regular expression operators like $, ^, etc. Which have their own respective purposes.
advertisement

10. Which of the following does not support regular expressions?
a) sed
b) awk
c) emacs
d) none of the mentioned
View Answer

Answer: d
Explanation: There are many UNIX tools including vi, Emacs, sed, awk and modern programming languages which support regular expressions.

Sanfoundry Global Education & Learning Series – Automata Theory.
To practice all areas of Automata Theory, here is complete set of 1000+ Multiple Choice Questions and Answers.

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 & technical discussions at Telegram SanfoundryClasses.