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.

File content:

17541   From Email      subscription@test.com      Inbound
Policy Manager  Envelope Analysis
Profiler
17541   From Email      subscription@yahoo.com      Inbound
Policy Manager  Envelope Analysis
Profiler
17541   From Domain      test.co.uk      Inbound
Policy Manager  Envelope Analysis
Profiler
17541   From Domain      yahoo.co.uk      Inbound
Policy Manager  Envelope Analysis
Profiler
17541   From Email      subscription@test.com      Inbound
Policy Manager  Envelope Analysis
Profiler

I use that command to extract e-mails and convert them to the new format,but I'm not able to extract domains. I use "sort -u" because some mails are duplicate in the file.

cat 1| grep -E -o "\b[a-zA-Z0-9.-]+@[a-zA-Z0-9.-]+\.[a-zA-Z0-9.-]+\b"|sed -e 's/^/E,/'|sort -u

Expected view after grep domains:

test.co.uk
yahoo.co.uk
share|improve this question
    
What kind of output are you expecting? –  Bernhard Oct 16 '12 at 7:30
    
I get this on three separate lines when I try E,subscription@test.com E,subscription@yahoo.com E,subscription@test.com . How does that differ from what you want? –  Nifle Oct 16 '12 at 7:34
    
I edit my requested. –  Kalin Borisov Oct 16 '12 at 8:06
add comment

2 Answers

up vote 0 down vote accepted

Your grep expression is fine, it's the sed one that doesn't work, change it to:

< 1 grep -Eo '\b[a-zA-Z0-9.-]+@[a-zA-Z0-9.-]+\.[a-zA-Z0-9.-]+\b' | sed -e 's/[^@]*@//' | sort -u

Assuming the input file is called 1. You could also do the whole thing with grep:

< 1 grep -Eo '\b[a-zA-Z0-9.-]+@[a-zA-Z0-9.-]+\.[a-zA-Z0-9.-]+\b' | grep -Eo '[^@]+$' | sort -u
share|improve this answer
    
Yes, that really work good thanks. –  Kalin Borisov Oct 17 '12 at 6:48
add comment

This awk one-liner gives the output that you desire

awk '/From Email/ { if( !match($4,"@") ){ print $4 } }' inputfile

It selects the lines containing 'From Email' and checks whether the fourth column contains a @. You can use match with regular expressions to match it to a domain and not a e-mailaddress if you like.

share|improve this answer
    
Thank you Bernard but that not work. There is not output. –  Kalin Borisov Oct 16 '12 at 8:30
    
I have mistake in the description of the question now is correct. When is domain are present like that "17541 From Domain test.co.uk Inbound" –  Kalin Borisov Oct 16 '12 at 8:33
    
And I get solution for my self thank you you answer give me the right direction where is my error. –  Kalin Borisov Oct 16 '12 at 8:36
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.