Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - General
User Name
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.


  Search this Thread
Old 01-08-2008, 09:37 AM   #1
Registered: Mar 2004
Distribution: debian...
Posts: 31

Rep: Reputation: 16
Need help with grep syntax and reg exp

I have been banging my head against this for a few days. I don't know much about regular expressions and my original thought was just to use grep to take the content below and show a few key facts from it.

So from this jumble mess (a converted snmp trap to syslog):

Kiwi_Syslog_Daemon Original Address= community="kiwisyslog", enterprise=, enterprise_mib_name=ciscoCidsAlert, uptime=434027636, agent_ip=, version=Ver2,, cidsGeneralEventId=1193860087813417372,"Hex String=07 D8 01 08 09 16 24 00", cidsGeneralLocalTime="Hex String=07 D8 01 08 09 16 24 00","Hex String=07 D8 01 08 0F 16 24 00", cidsGeneralUTCTime="Hex String=07 D8 01 08 0F 16 24 00",, cidsGeneralOriginatorHostId=ciscoasaIPS,, cidsAlertSeverity=low,, cidsAlertAlarmTraits=2147483648,"ICMP Network Sweep w/Echo", cidsAlertSignatureSigName="ICMP Network Sweep w/Echo",, cidsAlertSignatureSigId=2100,, cidsAlertSignatureSubSigId=0,, cidsAlertSignatureVersion=S2,, c...

to something like this? 2100 low ICMP Network Sweep w/Echo

So basically taking this out of it and creating a string of output, but without the syntax to grep the stuff out I'm lost...

Original Address=
cidsAlertSignatureSigName="ICMP Network Sweep w/Echo"

I have looked at snmptt for this and really the specific need here is so basic I would like to do it this way, also I'm really hoping to figure this out as a learning experience. I have tried grepping the file for things like $agent_ip (it just does nothing) and agent_ip (it returns the whole thing as output). Any ideas?
Old 01-08-2008, 09:58 AM   #2
Senior Member
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
awk ' BEGIN{FS="[,]"}
  for ( i=1 ; i<=NF;i++ ){
    if ( match($i,"Original Address=") ) {
         n=split( substr($i , RSTART) , a," ")
         print a[1],a[2]
    }else if ( $i ~ /cidsAlertSignatureSigId|cidsAlertSeverity|cidsAlertSignatureSigName/ ) {
        print $i    
}' "file"
# ./
Original Address=
 cidsAlertSignatureSigName="ICMP Network Sweep w/Echo"
Old 01-08-2008, 10:28 AM   #3
Registered: Mar 2004
Distribution: debian...
Posts: 31

Original Poster
Rep: Reputation: 16
holy cow that was quick. Thank you very much.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
GREP - reg exp to find words ending with .V and .TO vikram_cvk Linux - Server 5 12-22-2006 01:47 PM
python reg exp help Bopi Programming 1 12-03-2006 02:29 AM
Perl Reg Exp Question amytys Programming 1 12-09-2005 12:53 PM
prob with reg exp rajatgarg Programming 3 05-28-2004 09:21 AM
Reg Exp ugenn Programming 4 09-19-2002 12:01 PM > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 09:29 PM.

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