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


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
    Jan 28, 2019 at 10:03

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.