read

This week, while helping out the DebConf 15 team with some proofreading, I encountered a kind of diff I've never worked with before. A wdiff, or word diff, is intended for displaying word differences between text files. In the context where you are editing free-form text, rather than something like code, it makes a lot more sense than a more traditional unified or copied diff.

So far, so good! But, unfortunately, neither I nor the people who I was working with were able to find any tool out there that actually lets you apply a wdiff patch to a file - or even to blindly discard or accept all the changes inside a wdiff file.

As with most problems, it's nothing a sufficiently gross application of Perl can't solve. In case anyone in the future runs into this problem, I'm including the little Perl one-liner that will take a wdiff file on stdin and output the document with all changes applied. It's not pretty, and I haven't tested it that thoroughly, so use it with caution.

perl -ne '$_ =~  s/ ?\[-(?:[^\]]+)-\]//g; $_ =~ s/ ?\{\+([^\}]+)\+\}/ $1/g; print $_'
Blog Logo

Harlan Lieberman-Berg


Published

The postings on this site are my own and do not express the positions, strategies or opinions of Akamai.
The source for this blog can be found at gitlab.com.
Image

Setec Astronomy

Random rants on politics and discussions on tech.

Back to Overview