?
Solved

awk command?

Posted on 2004-08-24
6
Medium Priority
?
363 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
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
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.:
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…
Suggested Courses
Course of the Month15 days, 2 hours left to enroll

771 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