0

I have a directory with a bunch of files and each file contains millions of emails.

I need to get all the emails that don't fit with this pattern

 x.y@enron.com

x and y are letters.

I have this now but it doesn't match the correct emails

grep -P -r -x (?![a-z]*\.[a-z]*@enron)
  • Single quote your search pattern. Not only should this not match the correct emails, it should be throwing the following (or similar) error: -bash: ![a: event not found. You are trying to run nonsense commands in a subshell. – Jesse_b May 9 '18 at 14:22
  • Your grep will need to be a lot more sophisticated to separate out each email from the various files in order to display only those emails that don't have the pattern, versus every line as you have it now. – Jeff Schaller May 9 '18 at 14:25
  • 1
    Emails, as in full messages, or just email addresses? – ilkkachu May 9 '18 at 14:27
  • i am trying this now grep -E -r -x [^.]*@[a-z]*\.com – Andres ZW May 9 '18 at 14:34
  • how can i rewrite (?![a-z]*\.[a-z]*@enron) to correct it? – Andres ZW May 9 '18 at 14:37
0

Answer

grep -Evr "[a-z]+\.[a-z]+@enron"

Explanation

-E - Use extended regex. (Allow some characters to be used without escaping them)

-v - Invert the matches. (Everything that doesn't match the pattern will be shown)

-r - Search files recursively.

[a-z]+\.[a-z]+@enron - Your regex just with + instead of *, as I expect that there must be some letters in each section.

  • 1
    This doesn't work at all. Maybe you were looking for grep -Evr? This will still show the body of the emails with the x.y@enron addresses though. – Jesse_b May 9 '18 at 14:28
  • It still wont work though, please test it. – Jesse_b May 9 '18 at 14:37
  • I had minimal test, can you please give me example on which it doesn't work? – Iskustvo May 9 '18 at 14:41
  • the -v is not my option. Now i notice that the files also contain the message that users wrote – Andres ZW May 9 '18 at 14:41
  • 1
    Thank you but that is not helping very much. My current regex catches that correctly. You mentioned messages in the content as well and that's why I asked you for the sample. – Iskustvo May 9 '18 at 14:59

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.