Solved

awk command?

Posted on 2004-08-24
6
361 Views
Last Modified: 2010-04-21

I have a command that i use that i got from tfewster, works Great, problem is i cannot use it on compressed files, is there a way to use this on compressed files with uncompressing them, i use zcat and zgrep no problem but new to awk.



awk ' substr($0,1,160) ~ /my.domain.com/  ' logfiles22
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
  • 3
  • 2
6 Comments
 

Author Comment

by:bt707
ID: 11880061
Update:

Also is there a way to use a wildcard with this command,

such as  useing a wild card for the word domain in this case???     awk ' substr($0,1,160) ~ /my.****.com/  ' logfiles22
0
 
LVL 20

Expert Comment

by:Gns
ID: 11880119
Sure, in a way.
You can pipe the zcat output into the awk, and you can use ".*" as a wildcard... Somewhat like
zcat logfile22.Z | awk ' substr($0,1,160) ~ /my..*.com/  '
should work OK.

-- Glenn
0
 
LVL 5

Expert Comment

by:lemmeC
ID: 11880234
For matching the . literally, it has to be escaped.
So, you could use

awk ' substr($0,1,160) ~ /my\..*\.com/

This will match any string of the form my.*****.com. If this is not done, strings not having . will also match.

0
What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

 

Author Comment

by:bt707
ID: 11880343
Gns,

that is working Great, but still have one problem.

when is use the wild card  ".*"  i get to much,

Ex:
awk ' substr($0,1,160) ~ /pop..*.domain.com/  ' logfile1

when i run this command i get any thing that has the word pop in it, like popmaster, popman, ect, ect.

I want to only get lines that is   pop.    then after the (dot.) what ever domain is there, can i do this?

Thanks
0
 
LVL 20

Accepted Solution

by:
Gns earned 500 total points
ID: 11880393
Ok, you've just demonstrated lemmeCs point:-). Also note that the .* wildcard will match _as large as possible_... perhaps not what one wants... Slightly improved version:
zcat logfile22.Z | awk ' substr($0,1,160) ~ /my\..*\.com/  '

-- Glenn
0
 

Author Comment

by:bt707
ID: 11880456
Ok, got it, Works Great, I didn't see the post by LemmeCs at first, then when I tried it i kept getting a  > was asking for something, file name maybe?   I see he just left off the   '    at the very end, so what he put up works just fine also.

Thanks agian to all for the Great help!!!!
0

Featured Post

Industry Leaders: 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

My previous tech tip, Installing the Solaris OS From the Flash Archive On a Tape (http://www.experts-exchange.com/articles/OS/Unix/Solaris/Installing-the-Solaris-OS-From-the-Flash-Archive-on-a-Tape.html), discussed installing the Solaris Operating S…
I promised to write further about my project, and here I am.  First, I needed to setup the Primary Server.  You can read how in this article: Setup FreeBSD Server with full HDD encryption (http://www.experts-exchange.com/OS/Unix/BSD/FreeBSD/A_3660-S…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
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…

705 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