What he wants to end up with is:conduit permit tcp host 192.168.1.1 eq www any (hitcnt=57476) conduit permit tcp host 192.168.1.1 eq 139 host 192.168.2.1 (hitcnt=2)
Forget about writing to the database, for now. The more immediate problem is getting the program to "create" variables on the fly, depending upon how many "elements" a line contains. Assuming that this is even the right way to approach this problem; I don't know of any other way. Hence, this post. =)conduit permit tcp|host|192.168.1.1|eq|www|any|(hitcnt=57476) conduit permit tcp|host|192.168.1.1|eq|139|host|192.168.2.1|(hitcnt=2)
This prints:#!/usr/bin/perl -w use strict; my $in = "/home/trix/test"; my $out = "/home/trix/out"; use vars qw(@array @list); use vars qw ($host1 $host2 $conduit $permit $tcpudp $ip1 $ip2 $eq $port $hitcnt $line); open IN, "$in" || die "$!\n"; open OUT, ">$out" || die "$!\n"; while ($line = <IN>) { chomp $line; ($conduit, $permit, $tcpudp, $host1, $ip1, $eq, $port, $host2,$ip2 +, $hitcnt)=split( /\s/, $line); print OUT "$conduit $permit $tcpudp $host1\|$ip1\|$eq\|$port\|$hos +t2\|$ip2\|$hitcnt\n"; }
I thought that this was going to be a pretty easy thing to accomplish (for me), but I must say that I'm stumped. And it's not even my work! But I'm posting this, because I really want to learn how to do this. It seems like this could be pretty useful stuff.conduit permit tcp|host|192.168.1.1|eq|www|any|(hitcnt=57476) conduit permit tcp|host|192.168.1.1|eq|139|host|192.168.2.1
In reply to Variable number of words/fields in a line/record by Tuna
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |