
저는 리눅스 Centos 6-64를 사용하고 있습니다.
다음 명령을 어떻게 변경할 수 있습니까?, 입력 폴더 내에서 @로 작성된 이메일만 검색합니다.
grep -E -o -r "[A-Za-z0-9][A-Za-z0-9._%+-]+@[A-Za-z0-9][A-Za-z0-9.-]+\.[A-Za-z]{2,6}" /inputfolder/ | sort | uniq > "/outputfolder/result.txt"
아래의 모든 @ 형식으로 된 이메일을 검색하려면?
info@example.com
[email protected]
info(at)example.com
info[at]example.com
info%26%23064%3Bexample.com
info%40example.com
가능하다면 한 줄로 명령하세요. 감사합니다
답변1
-P
Perl 정규식 및 -i
대소문자를 구분하지 않는 경우 플래그를 사용할 수 있습니다 .
grep -Pi "[A-Z0-9][\w.%+-]+(?:@|@|\(at\)|\[at\]|%26%23064%3B|%40)[A-Z0-9][A-Z0-9.-]+\.[A-Z]{2,6}"
\w
약자[a-zA-Z0-9_]
설명:
[A-Z0-9] : 1 alphanum
[\w.%+-]+ : 1 or more alphanum, _, ., %, + or -
(?: : start non capture group
@ : literally @
| : OR
@ : html entity for @
| :
\(at\) :
| :
\[at\] :
| :
%26%23064%3B :
| :
%40 :
) :
[A-Z0-9] : 1 alphanum
[A-Z0-9.-]+ : 1 or more alphanum, . or -
\. : a dot
[A-Z]{2,6} : 2 upto 6 alpha (be aware that TLDs may have much more characters, see: https://www.iana.org/domains/root/db)
주어진 예에 대한 결과:
grep -Pi "[A-Z0-9][\w.%+-]+(?:@|@|\(at\)|\[at\]|%26%23064%3B|%40)[A-Z0-9][A-Z0-9.-]+\.[A-Z]{2,6}" file.txt
info@example.com
[email protected]
info(at)example.com
info[at]example.com
info%26%23064%3Bexample.com
info%40example.com