我有一个文本文件
file.txt
,内容为:
lord
blue
bird
The sky
reptile
lorwood
wood
我正在尝试使用命令
sed
和基本正则表达式来打印“lord”和“reptile”之间的行:
$ sed -n '/^lor/,/^rep/p' file.txt
但是,它会打印整个文件,就像
cat
一样。为什么?
我使用的
sed
版本是:
$ sed --version
sed (GNU sed) 4.8
Packaged by Debian
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Written by Jay Fenlason, Tom Lord, Ken Pizzini,
Paolo Bonzini, Jim Meyering, and Assaf Gordon.
This sed program was built with SELinux support.
SELinux is disabled on this system.
GNU sed home page: <https://www.gnu.org/software/sed/>.
General help using GNU software: <https://www.gnu.org/gethelp/>.
E-mail bug reports to: <[email protected]>.
紧接着
lor
行之后还有第二个 rep
行,因此 sed 将 lord
打印到 reptile
,然后打印 lorwood
直到文件末尾。