0
Tom.riddle@island.ac.kr
Ron_Weasley@island.ac.kr
harry2020@island.ac.kr

How to match these email addresses ? Any email address ending with island.ac.kr

3
  • 1
    A regular expression that matches them is .*@island.ac.kr or .*island.ac.kr. Which tool are you going to use to match them? Apr 12 at 6:45
  • 2
    @berndbausch Those would also match name@islandpac.kr.com though.
    – Kusalananda
    Apr 12 at 7:49
  • @Kusalananda oh no. You are right. Apr 12 at 11:46
2

You can use the following regex:

.*@island\.ac\.kr$

Example:

$ cat /tmp/111
Tom.riddle@island.ac.kr
Ron_Weasley@island.ac.kr
harry2020@island.ac.kr
itai@gmail.com
what.ever@island.ac.kr
abc@what.ac.kr
$ grep '.*@island\.ac\.kr$' /tmp/111
Tom.riddle@island.ac.kr
Ron_Weasley@island.ac.kr
harry2020@island.ac.kr
what.ever@island.ac.kr

The dots after the @ sign need to be escaped.

14
  • wow thank u so much!!!!!!
    – mimi ko
    Apr 12 at 8:00
  • You're welcome :)
    – Itai Ganot
    Apr 12 at 8:01
  • well /tmp/111 <- what does this mean btw? i couldnt clearly get it :/
    – mimi ko
    Apr 12 at 8:02
  • This is a temporary file where I've placed the examples you provided in your question.
    – Itai Ganot
    Apr 12 at 8:03
  • 1
    @mimiko Why not just use the regular expression that was mentioned in the answer?
    – Kusalananda
    Apr 12 at 8:15
0

Using awk and assuming that the input consists of one email address per line.

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

or, if you want lower-case output always,

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

This treats each line as a set of @-delimited fields. When the last field ($NF), turned into all lower-case, is exactly island.ac.kr, the line is printed.

Testing:

$ cat input.txt
Tom.riddle@island.ac.kr
Ron_Weasley@island.ac.kr
harry2020@island.ac.kr
itai@gmail.com
what.ever@island.ac.kr
abc@what.ac.kr
example@island.ac.kr.com
$ awk -F @ 'tolower($NF) == "island.ac.kr"' input.txt
Tom.riddle@island.ac.kr
Ron_Weasley@island.ac.kr
harry2020@island.ac.kr
what.ever@island.ac.kr

If you want to also match addresses like name@something.island.ac.kr, you could use awk like so:

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

Or, with grep and tr,

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

where tr is used to fold all characters into lower-case, and grep is then used to pick out the relevant lines.

Or just

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

if you don't mind possibly getting mixed case output.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.