我只是想测试一些我在杂志(Linux Shell Handbook)中看到的东西。我从来没有真正尝试过这样的事,但我知道这可能是有用的Perl正则表达式示例不起作用
的例子是
perl -n -e '/^The \s+(.*)$/ print "$1\n"' heroes.txt
在heroes.txt它
Catwoman
Batman
The Tick
Spider-Man
Black Cat
Batgirl
Danger Girl
Wonder Woman
Luke Cage
Ant-Man
Spider-Woman
,这应该显示刻度,但是我越来越
perl -n -e '/^The \s+(.*)$/ print "$1\n"' heroes.txt
syntax error at -e line 1, near "/^The \s+(.*)$/ print"
Execution of -e aborted due to compilation errors.
我在哪里出错?
速记打印 – imran 2013-03-27 15:14:53
之前需要分号不,[我的回答像]需要一个if语句(http://stackoverflow.com/a/15662424/465183) – 2013-03-27 15:21:10
谢谢你的作品,但我怎么能只显示一行 – geekcomputers 2013-03-27 15:25:34