So I have a long list of email and I want to search these based on just a few sections of the email string.

I want to try and search these emails more efficently so I want to match the start of the email. Is there a simple way to match the first character/first few characters, the @ and the following character and end of the email.

Here's an example search:


So then if I used a search on the following list it would only pull the top 2

[email protected]
[email protected]
[email protected]
[email protected]

1 Answer 1


With grep:

grep '^cal.*@a.*m$' input.txt

This matches lines beginning ^ with cal, followed by anything (.*), followed by @a, again followed by anything, with m at the end ($).

  • 1
    grep -x would get rid of the need for explicit anchors.
    – Kusalananda
    Commented Jan 28, 2019 at 10:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .