Regex 查找“;StringBetween";全目录linux cli

Regex 查找“;StringBetween";全目录linux cli,regex,linux,find,command-line-interface,Regex,Linux,Find,Command Line Interface,我有一个运行iredmail的邮件服务器 我们每天都会发送几份时事通讯,“退回”的时事通讯在vmail文件夹中 我想在不使用smtp的情况下从这些文件中提取“id”,因为我已经将整个邮件内容放在本地 "http://www.myserver.com/index.php?m=xxxxxxxxxx" 现在我想浏览目录中的所有文件,找到每个文件中第一个出现的“xxxxxxxxx”,并将其保存到文本文件中,以便从邮件列表数据库中删除这些id 如果可能,通过CLI 非常感谢。请尝试下面的命令以查找每个文

我有一个运行iredmail的邮件服务器

我们每天都会发送几份时事通讯,“退回”的时事通讯在vmail文件夹中

我想在不使用smtp的情况下从这些文件中提取“id”,因为我已经将整个邮件内容放在本地

"http://www.myserver.com/index.php?m=xxxxxxxxxx"
现在我想浏览目录中的所有文件,找到每个文件中第一个出现的“xxxxxxxxx”,并将其保存到文本文件中,以便从邮件列表数据库中删除这些id

如果可能,通过CLI


非常感谢。

请尝试下面的命令以查找每个文件中第一个出现的id

find . -maxdepth 1 -type f -exec grep -oP -m 1 '(?<=index\.php\?m\=)[^"]*' {} \; | sort -u

find-maxdepth 1-type f-exec grep-oP-m1'(?@AndreasHinderberger补充道:-)再次感谢。。我真是个雷格克斯的傻瓜:(回答a:D)
find         # command to find files are directories

.            # current directory(path on which the operation of find command is going to takes place)

-maxdepth 1  # don't search inside subdirectories.(ie; search only in the current directory)

-type f      # Only files

-exec grep -oP -m 1 '(?<=index\.php\?m\=)[^"]*' {} \;  # execute the grep command on only the founded files.

            -oP                          # (-o)print only the match,(-P) Perl-regex.
            -m 1                         # Grep to stop after first match occurs on each file.
            (?<=index\.php\?m\=)[^"]*    # A lookbehind is used here. It matches the text after `index.php?m=` upto the first occurrence of `"`. It helps to match the id's.
             {}                          # Founded files.
             \;                          # stops the find command.

sort -u      #  print only the unique id's.