Thread Datei-Erstellung nach String-Erkennung
(34 answers)
Opened by QWERTZ7 at 2011-03-31 08:21 2011-03-31T11:09:57 bianca das erinnert mich doch stark an könig einauge ;þ mag zwar nicht der weisheit letzer schluß sein, aber zumindest funzt's wie geplant. und nun überlegt euch mal die antwort auf so fragen wie "wieso hab ich nur eine datei, wieso hab ich nur einen eintrag in der datei etc pp blabla Code (perl): (dl
)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 #!/usr/bin/perl use strict; use warnings; use Data::Dumper; my $file = 'relevante_macs.txt'; my %switch_macs; # Open file with previously grepped data open (my $in, '<', $file) or die "Can't open $file: $!"; my @jet_macs = <$in>; # Build a hash with switches as key and macs as value foreach my $line (@jet_macs) { my ($mac, $switch) = split ' ', $line; push @{$switch_macs{$switch}}, $mac; } # What the fuck was this last push statement about? print Dumper \%switch_macs; # Now we got a nice hash, lets create the desired files foreach my $switch (keys %switch_macs) { if ( -e "$switch.cfg" ) { print "Sorry, won't overwrite an existing file\n"; next; } else { my $file_out; open($file_out, '>', "$switch.cfg") or die "Can't open $file_out: $!"; print $file_out "Here comes the header\n"; # Put the macs into the file foreach my $mac ( @{$switch_macs{$switch}} ) { print $file_out "show multiauth mac $mac\n"; } print $file_out "Here comes the footer\n"; close $file_out; } } Last edited: 2011-03-31 22:49:27 +0200 (CEST) root is a state of mind - k0resh
|