in reply to Perl script to match a regexp in the prior line and other multiple lines
If the positions of all the characters are very strict you may be able to write a program to determine those positions. Once you have those positions you could proceed with parsing the 'scan' lines. Here is a small code excerpt that you could use:
use strict ; use warnings ; my @pins = qw(31 22 13 84 95) ; my @positions = (40,42, 44, 46, 48) ; while (<DATA>) { my $line = $_; my $scan ; my $offset ; if ( $line =~ /(scan\d+)\s*(\d+)/ ) { $line = $line . <DATA> ; $scan = $1 ; $offset = $2 ; } for my $i (0..$#positions) { $_ = $positions[$i] ; my $pin = "p" . $pins[$i] ; if ( $line =~ /^.{$_}([HL]).*?\n.{$_}[\^]/ ) { print "$scan $offset $pin $1\n" ; } } } __DATA__ scan1 2965 H L H L H ^ scan2 2200 L H H L H ^ scan3 1100 H L L L L ^ scan4 1500 L L H H H ^ scan5 2800 H H L H H ^ ^
Output:
scan1 2965 p13 H scan2 2200 p22 H scan3 1100 p22 L scan4 1500 p13 H scan5 2800 p22 H scan5 2800 p95 H
|
|---|