0
我想从程序的输出中提取某些信息。但我的方法不起作用。我写了一个相当简单的脚本。grep in pipeline:为什么它不起作用
#!/usr/bin/env python
print "first hello world."
print "second"
使脚本可执行后,输入./test | grep "first|second"
。我期望它显示两个句子。但它没有显示任何东西。为什么?
我想从程序的输出中提取某些信息。但我的方法不起作用。我写了一个相当简单的脚本。grep in pipeline:为什么它不起作用
#!/usr/bin/env python
print "first hello world."
print "second"
使脚本可执行后,输入./test | grep "first|second"
。我期望它显示两个句子。但它没有显示任何东西。为什么?
逃避表达。
$ ./test | grep "first\|second"
first hello world.
second
还要记住的是,家当是#!/usr/bin/env python
,不只是#/usr/bin/env python
。
使用\|
代替|
./test | grep "first\|second"
哦,我输错那。感谢您的提醒。 – userd