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
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
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
the regexp matched. I dont want the hole line,
just the field that matches the regexp.
--
Hegga
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Well, this worked perfectly!
I'll reward the points
Thanks!
--
Hegga
I'll reward the points
Thanks!
--
Hegga
How about something like:
awk '{
for(i=1;i<=NF;i++) {
if($i ~ /^%..*%$) {
print $i
}
}
{' infile
awk '{
for(i=1;i<=NF;i++) {
if($i ~ /^%..*%$) {
print $i
}
}
{' infile
why not use grep ?
Cheers!
Sunny:o)