简体   繁体   中英

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. The reason it's not available is grep is being invoked from within a 3rd party library over which I have no control.

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. The backslashes above are required.

Grep version being used is:

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. 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

–三胞胎

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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