added export_opernam.pl
[spider.git] / perl / export_opernam.pl
diff --git a/perl/export_opernam.pl b/perl/export_opernam.pl
new file mode 100755 (executable)
index 0000000..2107c1a
--- /dev/null
@@ -0,0 +1,32 @@
+#!/usr/bin/perl
+#
+# export a standard ak1a opernam.dat file into CSV format.
+#
+# Copyright (c) 1999 Dirk Koopman G1TLH
+#
+#
+
+sub export
+{
+       my $rec = shift;
+       my @f = unpack "SA13A23SA12A6SSSSA1CSSSA1A80A1A13A1", $rec;
+       my $f;
+
+       # clean each field
+       for $f (@f) {
+               my @a = split m{\0}, $f;
+               $f = $a[0] if @a > 1;
+       }
+
+       print join '|', @f;
+       print "\n";
+}
+
+die "Need an filename" unless @ARGV;
+open IN, $ARGV[0] or die "can't open $ARGV[0] ($!)";
+
+while (sysread(IN, $buf, 196)) {
+       export($buf);
+}
+close IN;
+exit(0);