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
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.
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
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
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.
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
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
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.
6. State true or false:
Statement: A regular expression is a sequence of characters that represent a pattern.
a) true
b) false
View Answer
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
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.
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
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
Explanation: There are many other common regular expression operators like $, ^, etc. Which have their own respective purposes.
10. Which of the following does not support regular expressions?
a) sed
b) awk
c) emacs
d) none of the mentioned
View Answer
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.
- Buy Computer Science Books
- Practice Computer Science MCQs
- Apply for Automata Theory Internship
- Apply for Computer Science Internship
- Buy Automata Theory Books