CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Need a Custom or Prewritten Perl Program?: I need a program that...: parse file: Edit Log

New User

Feb 12, 2013, 7:37 AM

Views: 3323
parse file

I have text:

date=2013-01-02 time=23:59:59 devname=fg-abc device_id=FG3434 log_id=0038000007 type=traffic subtype=other pri=warning vd=root src= src_port=52752 src_int="interf" dst= dst_port=80 dst_int=unknown-0 SN=0 status=deny policyid=0 dst_country="Italy" src_country="Italy" service=HTTP proto=6 duration=0 sent=0 rcvd=0 msg="no session matched"

I want write to my DB(mysql row ) only informations like:
date=2013-01-02 time=23:59:59 type=traffic src= src_port=52752 src_int="interf" dst= dst_port=80

Other data must be ignore.
Sometimes the text will be different but always includes date,time,type,src_port,src_int,dst,dst_port
At the moment I have:

open (FILE ,"log.old"); 
while (<FILE>) {
chomp ();
my %zxc = split (/\b[= ]\b/);
foreach my $k (keys %zxc) {
print "$k: $zxc{$k}\n";
close (FILE);


status: deny
time: 23:59:59
date: 2013-01-02
log_id: 0038000007
policyid: 0
subtype: other
dst_country="Italy" src_country="Italy" service: HTTP
sent: 0
pri: warning
src_int="interf" dst:
dst_int: unknown-0
proto: 6
src_port: 52752
rcvd: 0
devname: fg-abc
duration: 0
dst_port: 80
device_id: FG3434
SN: 0
msg="no: session
vd: root
type: traffic

gut the problem is with text in ""
How can I parse this text ?

(This post was edited by q18 on Feb 12, 2013, 3:00 PM)

Edit Log:
Post edited by q18 (New User) on Feb 12, 2013, 2:59 PM
Post edited by q18 (New User) on Feb 12, 2013, 3:00 PM

Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives