in reply to Re^6: Finding the parent of a text in a file
in thread Finding the parent of a text in a file

#!/usr/bin/perl # http://perlmonks.org/?node_id=1140982 use strict; use warnings; my $filenameone = '1.pc.d'; # change to your main filename my $filenametwo = '2.pc.d'; # change to your secondary filename my @parents; # should work on linux, not sure what Solaris diff args are... open my $fh, '-|', "diff -U 999 $filenametwo $filenameone" or die $!; scalar <$fh>; # ignore first scalar <$fh>; # two lines while(<$fh>) { s/^([ +])(?=( *))// or next; $#parents = length($2) - 1; # truncate array push @parents, $_; $1 eq ' ' and next; defined and print, $_ = undef for @parents; }

If this doesn't work, please give a small test case that shows the failure.

Replies are listed 'Best First'.
Re^8: Finding the parent of a text in a file
by ExperimentsWithPerl (Acolyte) on Sep 06, 2015 at 15:52 UTC

    Thanks a lot Anonymous Monk.
    This works awesomely on my cofig files of lines 12500 each and gives output in no time.
    Apart from testing for regular differences ,I tried inserting a blank line in the config file, and it worked there too.
    Thanks once again. :)

      Forgot to mention its working on both Linus and Sun Solaris.