Solved

awk command?

Posted on 2004-08-24
6
357 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
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…

929 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now