Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

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.

share|improve this answer
    
Thanks @terdon - worked like a charm –  Praveen Sripati Nov 30 '12 at 13:28
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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