Solved

awk command?

Posted on 2004-08-24
6
359 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
  • 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 

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

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

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 …
In tuning file systems on the Solaris Operating System, changing some parameters of a file system usually destroys the data on it. For instance, changing the cache segment block size in the volume of a T3 requires that you delete the existing volu…
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…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

828 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