Solved

awk command?  modify

Posted on 2004-08-24
13
329 Views
Last Modified: 2010-04-21
thanks for the great help from  Cns and LemmeC on this one, i need to modify this command.

awk ' substr($0,1,120) ~ /@pop\..*.local.domain.com/  ' logfile1

awk ' substr($0,1,120) ~ /@pop\..*\.local.domain.com/  ' logfile1

when i run either of these commands i get the @pop. like i want but the way i'm useing the wildcard
i still get anything after the  @pop.

I want to get any word that is between the  @pop.  and the .domain.com

in other words i want to take this part of the line          @pop.local.domain.com
and get any lines that match this with any word in the place of local.

Thanks
0
Comment
Question by:bt707
  • 8
  • 5
13 Comments
 
LVL 5

Expert Comment

by:lemmeC
ID: 11880846
Make that
awk ' substr($0,1,120) ~ /@pop\..*\.domain.com/  ' logfile1


Note that after @pop, you have 'slash' 'dot' 'dot' 'star' 'slash' 'dot' followed by domain.com.
0
 
LVL 5

Expert Comment

by:lemmeC
ID: 11880869
bt707,
      If any more issues related to this question arise, ask them here itself. No need to create a new question.
0
 
LVL 5

Expert Comment

by:lemmeC
ID: 11880937
Correction. Make that
awk ' substr($0,1,120) ~ /@pop\..*\.domain\.com/  ' logfile1

Wherever . is to be literally matched, escape it with a slash ( \ ).
0
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:bt707
ID: 11881007
hello LemmeC,

I have tried it like this:

awk ' substr($0,1,120) ~ /@pop\..*\.domain.com/  ' logfile1

but i still get any line that has @pop. then anything after.

I need to get only the lines with  @pop.xxxxx.domain.com  (while the xxxx can be any word)

right now I'm getting stuff like      @pop.bc.com   @pop.abcd.com

I need to get the lines that has  @pop   and then   some word in front of the    .domain.com


Thanks agian
0
 
LVL 5

Expert Comment

by:lemmeC
ID: 11881180
Can you try this:

awk ' substr($0,1,120) ~ /@pop\.[a-zA-Z0-9]*\.domain\.com/  ' logfile1
0
 

Author Comment

by:bt707
ID: 11881332
tried it but when i use this i don't get anything back at all, just looks like it's searching for a while then exits back to # prompt.

0
 
LVL 5

Expert Comment

by:lemmeC
ID: 11881590
Oh, that's strange. Will look into it. Meanwhile, can you try this as well:

awk ' substr($0,1,120) ~ /@pop\..*\.domain\.com/  ' logfile1
0
 

Author Comment

by:bt707
ID: 11881628
that one got it printing out again but still getting  @pop.(anything)

Like   @pop.com.br

just can't get that   @pop.xxxx.domain.com
0
 
LVL 5

Expert Comment

by:lemmeC
ID: 11881828
I am confused. The script
awk ' substr($0,1,120) ~ /@pop\..*\.domain\.com/  ' logfile1
is working perfectly here.

The logfile1 contents I used were:
test@pop.maj.domain.com
test@pop.local.domain.com
test@pop.acc.com
abc@pop.sim.domain.com
abc@pop.com.br

and I got the output
test@pop.maj.domain.com
test@pop.local.domain.com
abc@pop.sim.domain.com


What are the contents of logfile1 you were using? What output did you get?
0
 

Author Comment

by:bt707
ID: 11882164
here is the exact command i'm using:

awk ' substr($0,1,120) ~ /@pop\..*\.oilfield\.slb\.com/  ' mail.log.7

i need to get the @pop xxxx  .oilfield.slb.com  

but i get lines like this from this search:

 D 3 ymhpqs@pop.com.br
rdcrfsfcgjojg@pop.com.br
jtamura@pop.abc.slb.com


I need the @pop and the .oilfiled.slb.com and what's between

i don't want to pull up anything that is not   @pop.(xxxx).oilfield.slb.com

thanks,


0
 
LVL 5

Accepted Solution

by:
lemmeC earned 500 total points
ID: 11882558
Well, its very strange. Again, I'm getting perfect results for the command you specified.

mail.log.7 has contents:
D 3 ymhpqs@pop.com.br
asdnasd@pop.adasd.oilfield.slb.com
rdcrfsfcgjojg@pop.com.br
dfasdkfj@pop.abcdef.slb.com
jtamura@pop.abc.slb.com
asdfasfd@pop.com.br
asdnasd@pop.adsd.oilfield.slb.com

The output at the command prompt on giving command awk ' substr($0,1,120) ~ /@pop\..*\.oilfield\.slb\.com/  ' mail.log.7
asdnasd@pop.adasd.oilfield.slb.com
asdnasd@pop.adsd.oilfield.slb.com


Anyway, I gotta go now (Its night here already). I'll get back to you later.
Meanwhile, could you check if it is possible to upgrade to a newer version (if available) of awk.
0
 

Author Comment

by:bt707
ID: 11887781
Hello lemmeC,

all is working Great.

guess I should of asked my question a different way, I knew that all the lines I was searching was getting messed up and what I needed was in the first part of the line so that is why I was using the   'substr($0,1,120)' part, I found out today from a co worker, that I could use awk a better way to get what I'm looking for.

Everything you gave me worked super, learned a lot today from you, a Big Thanks for that.

Here is what I'm using now, I didn't know that I could just tell awk to print the two columns that I wanted.

awk '$7 ~ /@pop.*+abc.com/ {print $6, $7;}'  mail.log.7 | grep -v abc | uniq

One question......what does the   '$7 after awk do??

Thanks again for a Super Job
0
 
LVL 5

Expert Comment

by:lemmeC
ID: 11889302
$7 represents the 7th word (or field) of a line. I guess that in your case. the search string is a substring of the 7th word of each line.
In general, $n represents the n-th word in a line. The only exception is $0 which represents the entire line.
If no field number is specified in the awk command, the entire line is searched.
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Problem Imaging Computers With Clonezilla 2 95
how to monitor remote shell execution on linux 9 104
cron job says it ran, no results 25 122
Solaris acount issues 44 28
Let's say you need to move the data of a file system from one partition to another. This generally involves dismounting the file system, backing it up to tapes, and restoring it to a new partition. You may also copy the file system from one place to…
Installing FreeBSD… FreeBSD is a darling of an operating system. The stability and usability make it a clear choice for servers and desktops (for the cunning). Savvy?  The Ports collection makes available every popular FOSS application and packag…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

828 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