本文介绍了Mac上的Sed正则表达式问题,在Linux上工作正常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这在Linux(Debian)上可以正常工作:
This works fine on Linux (Debian):
sed -e 's,^[ \t]*psd\(.*\)\;,,'
在Mac上,我相信我必须使用-E
标志而不是-e
:
On mac, I believe I have to use the -E
flag, instead of -e
:
sed -E 's,^[ \t]*psd\(.*\)\;,,'
但是正则表达式不匹配,因此不会删除我想要的行.
but the regexp does not match, and hence does not remove the lines I want.
有关如何解决此问题的任何提示?
Any tips on how to solve this?
样本输入:
apa
bepa
psd(cepa);
depa psd(epa);
psd(fepa gepa hepa);
对于该输入,预期输出为:
For that input, the expected output is:
apa
bepa
depa psd(epa);
推荐答案
-E
标志意味着使用扩展的正则表达式.您应该只使用-e
,就像在Linux上一样. Mac OS X中的sed
基于BSD sed,因此没有GNU扩展.
The -E
flag means to use extended regular expressions. You should just use -e
, as on Linux. The sed
in Mac OS X is based on BSD sed, so doesn't have the GNU extensions.
复制示例输入后:
[~ 507] pbpaste | sed -e 's,^[[:space:]]*psd\(.*\);,,'
apa
bepa
depa psd(epa);
这篇关于Mac上的Sed正则表达式问题,在Linux上工作正常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!