Hello, all.
I have a Diff question I'm hoping you all can help me with. I'm working with two files, which have some of the same data in them, and I need to be able to apply changes made in one file to the other one. I'm hoping to be able to use something like "patch", but in that case, I need to get a proper diff, which I'm stuck on.

The situation: The first file is a device configuration file, the second is a file that has just one section of the device's configuration. My users will be able to edit the second file (with just the partial config), which I will then need to be able to apply to the first file. Since this is a config file for a device, I can't put anything like marker symbols into the config, since the device won't accept them. Also, in the long term, I'd like to be able to take the configuration section from the user and apply it to multiple device configuration files, which is why I'm looking for something automated.

I've looked at Text::Diff and Algorithm::Diff, but since the line numbers (and total content) will be different between the two files, it doesn't look like either one of those will work. I thought about making a fake file from the main config file containing just the lines that match & then using Text::Diff, but then I'm faced with the problem of finding the matching lines, by which point I will have basically re-written Diff.

Do any of you have any ideas to make this simple and/or elegant? I can do brute force & ignorance, but I was hoping to avoid that approach.

Thanks much.


In reply to Making a Diff from a partial change by gclef

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.