250+ TOP MCQs on Regular Expression in UNIX and Answers

Automata Theory Multiple Choice Questions 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

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

Answer: b
Clarification: 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) /^$/

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

Answer: c
Clarification: 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) Both (a) and (b)
d) None of the mentioned

Answer: b
Clarification: 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

Answer: a
Clarification: 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) Both (a) and (b)
d) None of the mentioned

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

Answer: c
Clarification: 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

Answer: b
Clarification: 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

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

Leave a Reply

Your email address will not be published. Required fields are marked *