awk print only fields that matches an regexp

I have a txt file with som mail adressess that are collected out of my maildir,
now I want awk to print all the mail adressess that matches a regexp.
There is no logical system in the file, so awk will have to check every word.

The file looks something like this:
> an djfklds sdkfjdf %mailadress% dfklødf
to: "jherwkejrh" <%mailadress%>

But there is no system in the since it's been awk'ed out of
my maildir.
Can someone help me with this ?

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Hi hegga,

why not use grep ?

heggaAuthor Commented:
Because grep returns the whole line where
the regexp matched. I dont want the hole line,
just the field that matches the regexp.

Well, I can do it in perl for you. My awk knowledge isn't that good:

cat file | perl -ne 's/^.*\b(\w+\@\w+\.\w+)\b.*$/$1/g,print if /\w+\@\w+\.\w+/'

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
heggaAuthor Commented:
Well, this worked perfectly!
I'll reward the points


How about something like:

awk '{
   for(i=1;i<=NF;i++) {
      if($i ~ /^%..*%$) {
         print $i
{' infile
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux OS Dev

From novice to tech pro — start learning today.