#!/usr/bin/env perl # # SPDX-License-Identifier: Beerware # Wolfgang DM5WK Kroener wrote this file. As long as you retain this notice you # can do whatever you want with this stuff. If we meet some day, and you think # this stuff is worth it, you can buy me a beer in return. # # modified from perlmonks - TedPride - http://www.perlmonks.org/?node_id=559222 # modified from https://scruss.com/blog/2011/05/23/parsing-adif-with-perl/ # # Description: # Parse adif file, if a contact has one or more POTA_REF entries (delimited by # a comma), add SIG POTA and SIG_INFO with reference. Multiply contact such, # that every POTA_REF entry is a separate contact with own SIG_INFO. # Extendet adif file will be printed to stdout. # # Usage: # adif-pota2sig.pl logfile.adi > new-logfile.adi use strict; use warnings; # use filename.adi as parameter open(my $FH, '<', $ARGV[0]) or die "$ARGV[0]: $!"; while (<$FH>) { print; # fast forward past header last if m/\s+$/i; } my @entry = (); my @pota_refs = (); while (<$FH>) { push @entry, $_; if (m/\s+$/i) { # entry complete if (scalar(@pota_refs) > 0) { # add sig_info to each pota reference foreach my $ref (@pota_refs) { # print all except last print @entry[0 .. $#entry - 1]; # insert POTA SIG print "POTA\n"; print "" . $ref . "\n"; # print last print $entry[-1]; } } else { # no park reference in this entry print @entry; } # clear entry and pota refs for next entry @entry = (); @pota_refs = (); } elsif (m/^ my $val = (split(/>/))[-1]; chomp($val); # fill pota_refs with references @pota_refs = split(/,/, $val); chomp @pota_refs; } } close($FH);