135k views
4 votes
Which of the following commands uses correct syntax for matching the patterns bunk or bank at the end of a line of text?

a. grep 'b[au]nk$' myLine
b. grep "b[au]nk$" myLine
c. grep b[au]nk$ myLine
d. grep 'b[au]nk$" myLine

1 Answer

5 votes

Answer:

a. grep 'b[au]nk$' myLine

Step-by-step explanation:

grep is a command used for searching a specified pattern in a given text.

Our goal is to match the character sequence - bank or bunk at the end of line in a given line referenced by myLine.

The regular expression for the specified match criterion is:

b[au]nk$

The second character can be either a or u.

$ indicates match at end of line.

So the overall grep command is :

grep 'b[au]nk$' myLine

User DappWind
by
5.9k points