Link to home
Start Free TrialLog in
Avatar of hegga
hegga

asked on

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:
<%mailadress%>
> 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 ?

--
Hegga
Avatar of sunnycoder
sunnycoder
Flag of India image

Hi hegga,

why not use grep ?

Cheers!
Sunny:o)
Avatar of hegga
hegga

ASKER

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

--
Hegga
ASKER CERTIFIED SOLUTION
Avatar of Asby
Asby

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of hegga

ASKER

Well, this worked perfectly!
I'll reward the points

Thanks!

--
Hegga
How about something like:

awk '{
   for(i=1;i<=NF;i++) {
      if($i ~ /^%..*%$) {
         print $i
      }
   }
{' infile