LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 08-16-2006, 08:16 PM   #1
stakhous
Member
 
Registered: May 2003
Location: PA
Posts: 82

Rep: Reputation: 15
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!
 
Old 08-16-2006, 08:34 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Something like

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

maybe?

Cheers,
Tink
 
Old 08-16-2006, 09:29 PM   #3
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,780

Rep: Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081
I assume the mysterious looking awk command works, but for future reference the grep option is -v for --invert-match.
 
Old 08-16-2006, 09:42 PM   #4
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
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
 
Old 08-16-2006, 11:46 PM   #5
leandean
Member
 
Registered: Oct 2005
Location: Burley, WA
Distribution: Sabayon, Debian
Posts: 278

Rep: Reputation: Disabled
And I always thought "awk" was the call of a Channel-billed Cuckoo
 
Old 08-17-2006, 02:38 AM   #6
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
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
 
Old 08-17-2006, 02:54 AM   #7
pwc101
Senior Member
 
Registered: Oct 2005
Location: UK
Distribution: Slackware
Posts: 1,847

Rep: Reputation: 128Reputation: 128
so it's not short for awkward then?... I've been misled...
 
Old 08-17-2006, 02:58 AM   #8
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
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
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
bash script with grep and sed: sed getting filenames from grep odysseus.lost Programming 1 07-17-2006 11:36 AM
grep ?? can grep us variables? DaFrEQ Linux - Software 4 09-14-2005 12:22 PM
What does rpm -qa |grep th* (as compared to rpm -qa |grep th) display? davidas Linux - Newbie 2 03-18-2004 01:35 AM
"Undeleting" data using grep, but get "grep: memory exhausted" error SammyK Linux - Software 2 03-13-2004 03:11 PM
ps -ef|grep -v root|grep apache<<result maelstrombob Linux - Newbie 1 09-24-2003 11:38 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 08:15 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration