Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

awk print only fields that matches an regexp

Posted on 2003-10-22
5
Medium Priority
?
292 Views
Last Modified: 2010-04-22
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
0
Comment
Question by:hegga
5 Comments
 
LVL 45

Expert Comment

by:sunnycoder
ID: 9598614
Hi hegga,

why not use grep ?

Cheers!
Sunny:o)
0
 

Author Comment

by:hegga
ID: 9598730
Because grep returns the whole line where
the regexp matched. I dont want the hole line,
just the field that matches the regexp.

--
Hegga
0
 
LVL 1

Accepted Solution

by:
Asby earned 800 total points
ID: 9599016
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+/'
0
 

Author Comment

by:hegga
ID: 9599087
Well, this worked perfectly!
I'll reward the points

Thanks!

--
Hegga
0
 
LVL 7

Expert Comment

by:glassd
ID: 9599373
How about something like:

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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

824 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question