egrep和grep与美元的差异 [英] egrep and grep difference with dollar

查看:81
本文介绍了egrep和grep与美元的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在模式中使用\ $时,我难以理解grep end egrep的不同行为.

I'm having touble understanding the different behaviors of grep end egrep when using \$ in a pattern.

更具体地说:

grep "\$this->db" file   # works

egrep "\$this->db" file  # does not work

egrep "\\$this->db" file # works

有人可以告诉我原因还是链接一些解释?非常感谢.

Can some one tell me why or link some explanation? Thank you very much.

推荐答案

反斜杠被shell的转义处理所吞噬,因此在前两种情况下,正则表达式只是 $ this-> db .区别在于, grep 将不在正则表达式末尾的 $ 视为普通字符,而 egrep 则将其视为普通字符.与行尾匹配的正则表达式.

The backslash is being eaten by the shell's escape processing, so in the first two cases the regexp is just $this->db. The difference is that grep treats a $ that isn't at the end of the regexp as an ordinary character, but egrep treats it as a regular expression that matches the end of the line.

在最后一种情况下,双反斜杠导致反斜杠发送到 egrep .这会转义 $ ,因此将其视为普通字符而不是与行尾匹配.

In the last case, the double backslash causes the backslash to be sent to egrep. This escapes the $, so it gets treated as an ordinary character rather than matching the end of the line.

这篇关于egrep和grep与美元的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆