?
Solved

awk command?  modify

Posted on 2004-08-24
13
Medium Priority
?
343 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 2000 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This tech tip describes how to install the Solaris Operating System from a tape backup that was created using the Solaris flash archive utility. I have used this procedure on the Solaris 8 and 9 OS, and it shoudl also work well on the Solaris 10 rel…
Using libpcap/Jpcap to capture and send packets on Solaris version (10/11) Library used: 1.      Libpcap (http://www.tcpdump.org) Version 1.2 2.      Jpcap(http://netresearch.ics.uci.edu/kfujii/Jpcap/doc/index.html) Version 0.6 Prerequisite: 1.      GCC …
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.
Suggested Courses

764 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