Solved

awk command?

Posted on 2004-08-24
6
356 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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Java performance on Solaris - Managing CPUs There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".   In a multithreaded…
FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
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…

746 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

11 Experts available now in Live!

Get 1:1 Help Now