Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

this is the INPUT:

$ echo -e '<tr><td>XXX</td><td>XXX</td><td>XXX</td><td>XXX</td><td>XXX</td><td>XXX</td><td>XXX</td><td>XXX</td><td>someone.something@example.com</td></tr>\n<tr><td>YYY</td><td>YYY</td><td>YYY</td><td>YYY</td><td>YYY</td><td>YYY</td><td>YYY</td><td>YYY</td><td>foo.bar@example2.com</td></tr>'
<tr><td>XXX</td><td>XXX</td><td>XXX</td><td>XXX</td><td>XXX</td><td>XXX</td><td>XXX</td><td>XXX</td><td>someone.something@example.com</td></tr>
<tr><td>YYY</td><td>YYY</td><td>YYY</td><td>YYY</td><td>YYY</td><td>YYY</td><td>YYY</td><td>YYY</td><td>foo.bar@example2.com</td></tr>

this is the OUTPUT with SOME MAGIC!

$ echo -e '<tr><td>XXX</td><td>XXX</td><td>XXX</td><td>XXX</td><td>XXX</td><td>XXX</td><td>XXX</td><td>XXX</td><td>someone.something@example.com</td></tr>\n<tr><td>YYY</td><td>YYY</td><td>YYY</td><td>YYY</td><td>YYY</td><td>YYY</td><td>YYY</td><td>YYY</td><td>foo.bar@example2.com</td></tr>' | SOMEMAGIC
<tr><td>XXX</td><td>XXX</td><td>XXX</td><td>XXX</td><td>XXX</td><td>XXX</td><td>XXX</td><td>XXX</td><td>example.com</td></tr>
<tr><td>YYY</td><td>YYY</td><td>YYY</td><td>YYY</td><td>YYY</td><td>YYY</td><td>YYY</td><td>YYY</td><td>example2.com</td></tr>

My question: how can "SOMEMAGIC" remove the prefixes before "@" and the "@" itself?

The unique delimiter is the

"</td><td>"

XXX and YYY could be anything, so it could be ex.: "someone.something@example.com" too :\

p.s.: So the question is, how can someone remove the prefix from:

someone.something@example.com

so it will be:

example.com

in this table?

share|improve this question
up vote 1 down vote accepted

Try this:

$ echo -e '<tr><td>XXX</td><td>XXX</td><td>XXX</td><td>XXX</td><td>XXX</td><td>XXX</td><td>XXX</td><td>XXX</td><td>someone.something@example.com</td></tr>\n<tr><td>YYY</td><td>YYY</td><td>YYY</td><td>YYY</td><td>YYY</td><td>YYY</td><td>YYY</td><td>YYY</td><td>foo.bar@example2.com</td></tr>' | \
awk -F'</td><td>' 'gsub(/.*@/,"",$9)' OFS='</td><td>'
<tr><td>XXX</td><td>XXX</td><td>XXX</td><td>XXX</td><td>XXX</td><td>XXX</td><td>XXX</td><td>XXX</td><td>example.com</td></tr>
<tr><td>YYY</td><td>YYY</td><td>YYY</td><td>YYY</td><td>YYY</td><td>YYY</td><td>YYY</td><td>YYY</td><td>example2.com</td></tr>

</td><td> delimiter split the line into 9 fields. The email is field number 9th, you can remove all characters before @ in 9th field to get desired output.

If you don't have to use awk, you can try perl:

perl -pe 's#(.*)<td>.*@(.*)#$1<td>$2#'
share|improve this answer
    
Simply. wow.. Bless you. – evachristine May 3 '14 at 19:34

This should work:

echo '....' | sed 's,>[^<@]*@,>,g'
share|improve this answer

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.