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入力の各行に1つのEメールアドレスが含まれているとします。

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

気に入らない場合は大文字と小文字を混ぜて出力することが可能です。

関連情報