Seems to do what you showed. If not, please say why and provide a more extensive test case.
#!/usr/bin/perl # http://perlmonks.org/?node_id=1140982 use Algorithm::Diff qw(traverse_sequences); use strict; use warnings; my $file1 = <<END; system security management-ip protocol internal shutdown allow entry 1 snmp ok exit END my $file2 = <<END; system security management-ip protocol internal shutdown allow entry 1 snmp failed exit END sub fullpath { my @full; my @answer; for my $line ( shift() =~ /.+\n/g ) { $line =~ /^( *)/; $#full = length($1) - 1; # truncate array push @full, $line; push @answer, join '', grep defined, @full; } return \@answer; } my $full1 = fullpath($file1); my $full2 = fullpath($file2); traverse_sequences( $full1, $full2, { DISCARD_A => sub {print $full1->[shift()], "\n"}, } );
In reply to Re: Finding the parent of a text in a file
by Anonymous Monk
in thread Finding the parent of a text in a file
by ExperimentsWithPerl
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |