简体   繁体   English

什么是sed -E和sed -e之间的区别

[英]Whats the difference between sed -E and sed -e

I'm working on some old code and I found that I used to use 我正在研究一些旧代码,我发现我曾经使用过

sed -E 's/findText/replaceWith/g' #findText would contain a regex

but I now try 但我现在试试

sed -e 's/findText/replaceWith/g'

It seems to do the same thing, or does it? 它似乎做同样的事情,或者它呢? I kinda remember there being a reason I done it but I can't remember and doing "man sed" doesn't help as they don't have anything about -E only -e that doesn't make much sense ether. 我有点记得有一个原因我做了但我不记得并且做“man sed”没有帮助,因为他们没有任何关于-E only -e,这没有太多意义以太。

-e, --expression=script
  Append the editing commands in script to the end of 
  the editing command script. script may contain more 
  than one newline separated command.

I thought -e meant it would match with a regex... 我想 - 这意味着它会与正则表达式相匹配......

GNU sed version 4.2.1

From source code, -E is an undocumented option for compatibility with BSD sed. 从源代码来看, -E是一个未记录的选项,用于与BSD sed兼容。

/* Undocumented, for compatibility with BSD sed.  */
case 'E':
case 'r':
  if (extended_regexp_flags)
    usage(4);
  extended_regexp_flags = REG_EXTENDED;
  break;

And from manual , -E in BSD sed is used to support extended regular expressions. 手册中-E in BSD sed用于支持扩展正则表达式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM