What I want to do is, diff 2 files and write the diff output to 3 different files.
I can tell diff to format its output like:
diff a.txt b.txt --new-line-format=... --old-line-format=... --unchanged-line-format=...
And using this:
diff a.txt b.txt --new-bla-bla="echo %l>new.txt" --old--="echo %l>old" ...
I can output to 3 different files, except the double quotes don’t appear.
I want to do this as minimally as possible, so running 3 diffs, etc are not an option
Here’s a solution that is maybe a little longer, but more robust as it avoids the need for
eval:This works by prefixing each of the new, old, and unchanged lines (respectively) with the file descriptor of the file we will add them to. We then parse the output using
read, and echo the line to the correct file descriptor, each of which is redirected to the correct output file.