]> dxcluster.net Git - spider.git/commitdiff
*** empty log message ***
authorminima <minima>
Tue, 1 Nov 2005 13:17:59 +0000 (13:17 +0000)
committerminima <minima>
Tue, 1 Nov 2005 13:17:59 +0000 (13:17 +0000)
perl/log2csv.pl [new file with mode: 0755]

diff --git a/perl/log2csv.pl b/perl/log2csv.pl
new file mode 100755 (executable)
index 0000000..eb6c41d
--- /dev/null
@@ -0,0 +1,56 @@
+#!/usr/bin/perl -w
+#
+# convert a DXSpider Log file to csv format
+#
+# usage: log2csv.pl <filename> ...
+#
+# Copyright (c) 2005 Dirk Koopman G1TLH
+#
+# $Id$
+# 
+# make sure that modules are searched in the order local then perl
+use strict;
+
+BEGIN {
+       # root of directory tree for this system
+       use vars qw($root $is_win);
+       $root = "/spider"; 
+       $root = $ENV{'DXSPIDER_ROOT'} if $ENV{'DXSPIDER_ROOT'};
+       
+       unshift @INC, "$root/perl";     # this IS the right way round!
+       unshift @INC, "$root/local";
+
+       $is_win = ($^O =~ /^MS/ || $^O =~ /^OS-2/) ? 1 : 0; # is it Windows?
+}
+
+use DXUtil;
+
+die "usage: log2csv.pl <filename> ....\n" unless @ARGV;
+
+my $crnl = $is_win ? "\015\012" : "\012";
+
+for (@ARGV) {
+       unless (open IN, $_) {
+               print STDERR "cannot open $_ $!\n";
+               next;
+       }
+       while (<IN>) {
+               chomp;
+               s/([\%\"\'\x00-\x1f\x7f-\xff])/sprintf("%%%02X", ord($1))/eg;
+               my @line =  split '\^';
+               my $date = unpad cldate($line[0]);
+               my $time = unpad ztime($line[0], 1);
+               print "$date\t$time\t$line[1]";
+               shift @line;
+           shift @line;
+               while (@line < 3) {
+                       unshift @line, '';
+               }
+               print "\t", join("\t", @line), $crnl;
+       }
+       close IN;
+}
+
+
+
+