I don't know what you mean by "nice and neat"? Do you want only a part of the information from each line in firewall.txt? If so, then you probably want to check
split(), or maybe want to use
regular expressions. You will have to give us an example of "very ugly and not very clean" and then an example of "nice and neat" if you want more help...
I have a comment on your script as it is: you are reading all of firewall.txt into memory, which can bring problems if the file gets very large. It's better if you open it and then iterate through it searching the lines that interest you. It's also a good idea to check the return values of your open() calls:
open(FW_LOG, $firewall_log)
or die "$firewall_log open() failed: $!";
open(MYNEWFILE, ">>$my_new_log")
or die "$my_new_log open() failed: $!";
while ($line = <FW_LOG>) {
if ($line =~ /kernel Temporarily blocking host/ || $line =~ /block
+ed/) {
# your line transformations would go here...
print MYNEWFILE $line;
}
}
close(FW_LOG) or die "$firewall_log close() failed: $!";
close(MYNEWFILE) or die "$my_new_log close() failed: $!";
hope this helps,
update: added closing curly brace for if, removed colon at the end of filename $my_new_log