I have the following assignment:
Words of a song are in a file called stairway.txt. Which of the following lines will be printed out after this command:
grep -E '(^.{4})(.{2}).*[ ]\2' stairway.txt
(a) Yes, there are two paths you can go by but in the long run
(b) Its just a spring clean for the May queen.
(c) Don't be alarmed now.
(d) If there's a bustle in your hedgerow.
(e) Theres still time to change the road you're on.
I don't understand what does the \2
at the end mean?
It is a backreference.
From http://www.selectorweb.com/grep_tutorial.html:
Backreference is an expression \n where n is a number. It matches the contents of the n'th set of parentheses in the expression.
Also, the answer is (d):
$ grep -E '(^.{4})(.{2}).*[ ]\2' test.txt
If there's a bustle in your hedgerow.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With