Linux에서 정규식을 사용하여 여러 이메일 주소를 일치시키는 방법은 무엇입니까?

Linux에서 정규식을 사용하여 여러 이메일 주소를 일치시키는 방법은 무엇입니까?
[email protected]
[email protected]
[email protected]

이 이메일 주소를 일치시키는 방법은 무엇입니까? island.ac.kr로 끝나는 모든 이메일 주소

답변1

다음 정규식을 사용할 수 있습니다.

.*@island\.ac\.kr$

예:

$ cat /tmp/111
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
$ grep '.*@island\.ac\.kr$' /tmp/111
[email protected]
[email protected]
[email protected]
[email protected]

기호 뒤의 점은 @이스케이프되어야 합니다.

답변2

awk입력의 각 줄에 하나의 이메일 주소가 포함되어 있다고 가정하고 사용하세요 .

awk -F @ 'tolower($NF) == "island.ac.kr"' input.txt

혹은 항상 소문자로 출력하고 싶다면,

awk -F @ 'tolower($NF) == "island.ac.kr" { print tolower($0) }' input.txt

@이는 각 행을 구분된 필드 집합으로 처리합니다 . 마지막 필드( $NF)가 모두 소문자( )인 경우 island.ac.kr해당 행이 인쇄됩니다.

시험:

$ cat input.txt
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
$ awk -F @ 'tolower($NF) == "island.ac.kr"' input.txt
[email protected]
[email protected]
[email protected]
[email protected]

유사한 주소도 일치시키려면 다음과 같이 사용할 [email protected]수 있습니다 .awk

awk -F @ 'tolower($NF) ~ /island\.ac\.kr$/'

또는 greptr,

tr '[:upper:]' '[:lower:]' <input.txt | grep 'island\.ac\.kr$'

여기서는 tr모든 문자를 소문자로 축소한 다음 grep관련 줄을 선택하는 데 사용됩니다.

그렇지 않으면

grep -i 'island\.ac\.kr$' input.txt

마음에 들지 않으면 대소문자를 혼합하여 출력하는 것이 가능합니다.

관련 정보