LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   I need some help with Grep (https://www.linuxquestions.org/questions/linux-general-1/i-need-some-help-with-grep-474578/)

stakhous 08-16-2006 08:16 PM

I need some help with Grep
 
Hello,


I am trying to read through my flooded firewall logs. So far the majority of my log is filled with
192.168.1.23,138 -> <my gateway>

Very annoying and preventing the logging of this sort of traffic is another story. As for now, I want to know how to sort through this firewall log and pick out only the IPs that do not start with 192.

So far I have,

awk '/ / {print $6}' ./firewall.log | grep "192*"
--outputs----
192.168.1.23,138
192.168.1.23,138
192.168.1.23,138
....
-------------

which gives me the undesired list of hundreds of 192 ips. (The IP is by itself in field 6)

now there has to be an easy way to display only the ips in field 6 that do not start with 192?

Thanks everyone!

Tinkster 08-16-2006 08:34 PM

Something like

awk '$6 !~ /^192\./ ' firewall.log

maybe?

Cheers,
Tink

ntubski 08-16-2006 09:29 PM

I assume the mysterious looking awk command works, but for future reference the grep option is -v for --invert-match.

Tinkster 08-16-2006 09:42 PM

Heh. What is mysterious about the awk command? :}

If
Code:

'$6
Field number six (by default white-space separates fields)
Code:

!~
is not like
Code:

/^192\./
a string beginning with 192 and a literal '.'
print the line (awks default action).


Cheers,
Tink

leandean 08-16-2006 11:46 PM

And I always thought "awk" was the call of a Channel-billed Cuckoo :)

Tinkster 08-17-2006 02:38 AM

Quote:

Originally Posted by leandean
And I always thought "awk" was the call of a Channel-billed Cuckoo :)

Heh. It's actually from the first letters of the last names of
the programmers, Aho, Weinberger & Kerninghan.
They might as well have named it wak, or kaw, or
something less easily pronounced like wka :}


Cheers,
Tink

pwc101 08-17-2006 02:54 AM

so it's not short for awkward then?... I've been misled... ;)

Tinkster 08-17-2006 02:58 AM

Hehe. No, it's misspelt short for awkesome :}

awk rocks. Small, clear, lightweight. Often quite suitable for
tasks that other may think a perl-thing.


Cheers,
Tink


All times are GMT -5. The time now is 01:12 AM.