Retrieving email address from a log file

1

I have a log file which contains a lot of text as shown below. Would like to extract the email address which falls between emailAddress and status strings. I am open to any option which runs on Ubuntu, but would like to automate it.

bouncedRecipients\":[{\"emailAddress\":\"praveen@gmail.com\",\"status

Praveen Sripati

Posted 2012-11-30T13:05:11.627

Reputation: 1 385

Answers

1

Here you go:

perl -ne 'if(/emailAddress..:..(.+?)\\\"/){print "$1\n"}' logfile.txt

This Perl snippet will go through the file line by line and look for the string "emailAddress" followed by:

  • any two characters (..), this will match \",
  • :,
  • any two characters (..), this will match \".

It then saves the following characters (until the next ") into $1. Finally, it prints $1.

NOTE: This assumes that every email address in your logfile has the same format as what you have given in your question.

terdon

Posted 2012-11-30T13:05:11.627

Reputation: 45 216