7

我有以下任务:

一首歌的歌词在一个名为 stairway.txt 的文件中。在此命令之后将打印出以下哪几行:

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.

不明白\2结尾是什么意思?

4

1 回答 1

15

这是一个反向引用。

来自http://www.selectorweb.com/grep_tutorial.html

反向引用是一个表达式 \n 其中 n 是一个数字。它匹配表达式中第 n 组括号的内容。

此外,答案是(d):

$ grep -E '(^.{4})(.{2}).*[ ]\2' test.txt
If there's a bustle in your hedgerow.
于 2012-04-14T09:29:02.237 回答