in reply to Re^2: Preserving "Valid" Data?
in thread Preserving "Valid" Data?

Try this. I changed two of the nan to just na to maintain column alignment.

#!/usr/bin/perl # http://perlmonks.org/?node_id=1186932 use strict; use warnings; my $high = 0; while(<DATA>) { $high < $_ and $high = $_ for /SATID (\d\d)/g; # middle s/SATID (\d\d) .{17}SIGNAL \d\d \K {35}(?= SATID (\d\d))/SATID @{[ $1 + $2 >> 1]} VAL1 na VAL2 nan SIGNAL na/g; # beginning s/\d:\d\d:\d\d \K {35}(?= SATID (\d\d))/SATID @{[ $1 - 1]} VAL1 na VAL2 nan SIGNAL na/; # end while( /.*SATID (\d\d)/ and $1 < $high ) { my $nextnumber = $1 + 1; s/$/ SATID $nextnumber VAL1 na VAL2 nan SIGNAL na/; } print; } __DATA__ Timestamp: 00:47:14 SATID 13 VAL1 28 VAL2 227 SIGNAL 37 + SATID 15 VAL1 22 VAL2 265 SIGNAL 30 SATID 16 VA +L1 22 VAL2 265 SIGNAL 30 Timestamp: 00:48:14 SATID 13 VAL1 28 VAL2 227 SIGNAL 37 + SATID 15 VAL1 22 VAL2 265 SIGNAL NA SATID 16 VA +L1 22 VAL2 265 SIGNAL 30 Timestamp: 00:49:14 SATID 14 VAL1 +22 VAL2 265 SIGNAL 30

Replies are listed 'Best First'.
Re^4: Preserving "Valid" Data?
by coding1227 (Novice) on Apr 05, 2017 at 04:34 UTC
    thanks! It looks like it might work well =)