简体   繁体   English

当-F不可用时,防止grep解析正则表达式语法

[英]Preventing grep from parsing regex syntax when -F is not available

I have a situation where I have to use grep to do some string matching, and the option to use the -F switch is not available. 我遇到一种情况,我必须使用grep进行一些字符串匹配,并且使用-F开关的选项不可用。 The reason it's not available is grep is being invoked from within a 3rd party library over which I have no control. 它不可用的原因是grep正在我无法控制的第3方库中调用。

The string I'm trying to match is exactly 我要匹配的字符串恰好是

0 2 * * * /usr/bin/find /data/app-logs/ -mindepth 1 -mtime +14 -a \\( -name "*.log*" -o -name "*.out*" -o -name "*.err*" \\) -delete

, so a crontab entry. ,因此是crontab条目。 The backslashes above are required. 上面的反斜杠是必需的。

Grep version being used is: 使用的Grep版本是:

grep (GNU grep) 2.5.1

I've tried escaping all of the [*\\.] characters, as I believe that's all that needs escaping with regular grep, but to no avail. 我已经尝试过转义所有[*\\.]字符,因为我认为这是需要用常规grep进行转义的所有方法,但无济于事。 Would appreciate any help here. 希望在这里有任何帮助。 I'm sure it's something small I'm missing. 我确定这是我所缺少的小东西。

grep '0 2 \* \* \* /usr/bin/find /data/app-logs/ -mindepth 1 -mtime +14 -a \\( -name "\*\.log\*" -o -name "\*\.out\*" -o -name "\*\.err\*" \\) -delete' testfile

–三胞胎

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

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