Solved

awk command?  modify

Posted on 2004-08-24
13
326 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
 

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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 Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Hello fellow BSD lovers, I've created a patch process for patching openjdk6 for BSD (FreeBSD specifically), although I tried to keep all BSD versions in mind when creating my patch. Welcome to OpenJDK6 on BSD First let me start with a little …
FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
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…

895 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now