Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 352
  • Last Modified:

awk command? modify

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
bt707
Asked:
bt707
  • 8
  • 5
1 Solution
 
lemmeCCommented:
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
 
lemmeCCommented:
bt707,
      If any more issues related to this question arise, ask them here itself. No need to create a new question.
0
 
lemmeCCommented:
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!

 
bt707Author Commented:
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
 
lemmeCCommented:
Can you try this:

awk ' substr($0,1,120) ~ /@pop\.[a-zA-Z0-9]*\.domain\.com/  ' logfile1
0
 
bt707Author Commented:
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
 
lemmeCCommented:
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
 
bt707Author Commented:
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
 
lemmeCCommented:
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
 
bt707Author Commented:
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
 
lemmeCCommented:
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
 
bt707Author Commented:
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
 
lemmeCCommented:
$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

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 8
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now