开发者

Regex sub-expression matching with Find + emacs-regex mode

I'm trying to find some compressed log files, and do some operations on them. I can't use ls because they are thousands of files in the directory and BASH throws a 'argument list too long' error. This has brought me to find, but I'm having trouble with my regex.

Here is the whole find command

find $i -regex '.*logfile_MP[0-9]-GW0[0-9]_2010-09-\(\([7-9]\)|\(1[0-9]\)|\(2[0-3]\)\)-.*' -exec ls {} \;

I actually need to go through several log directories, so $i com开发者_开发百科es from a BASH loop to go through all the directories. Right now, I'm just trying to list the files, so I know I have the right ones; I'll amend my -exec statement once I get it working.

The problem relates to the parentheses section:

\(\([7-9]\)|\(1[0-9]\)|\(2[0-3]\)\)

I'm trying to match a range of days (7-23). From what I understand about Emacs-regex mode, I have to escape all parentheses. The rest of the regex is working because if I replace the parentheses section with just a number (ex. 7), it works fine.

Can anyone help me create a regex sub-expression to match 7-23?

Thanks.


I think you're on the right track, just missing a \ in front of each of the |:

\([7-9]\|1[0-9]\|2[0-3]\)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜