Solved

awk command?  modify

Posted on 2004-08-24
13
327 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

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

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Suggested Solutions

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…
Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
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.

803 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