Emacs: Comparing Two Regions From Two Files

So I was compiling some useful database-related routines that I have used in various places (with MySQL and SQLite so far) over the years into a set of common modules, so that I could easily find the latest and best-tested versions of them for future projects. Then I came to a routine with two versions of a few dozen lines each, and I was trying to figure out a way of doing a diff on them without writing them out to temporary files. I have an Emacs command called “make-command-buffer”, which I can use for example to create a buffer for entering and executing shell commands, and collecting their output. It was easy enough to copy and paste both routines into the buffer, but now how do I put them both into one diff command? There is a shell feature called “here-docs”, which lets you include the standard-input data for a command directly following the command: «cmd» <<«marker» ... data ... «marker» where the «marker» is some word that does not occur in the data. But I want to have two of these, like this: diff -u <<EOD1 <<EOD2 ... version 1 ... EOD1 ... version 2 ... EOD2 You can do something like that in Perl, but it doesn’t work in the shell. Hunting around on line reminded me why: because you can only have one standard input. But in the Bash man page, there is a syntax for redirecting arbitary file descriptors, letting you have any number of heredocs. So, combining this with the ability to give a command a file name that corresponds to an already-open file descriptor, I finally got this to work: diff -u /dev/fd/8 /dev/fd/9 8<<EOD1 9<<EOD2 ... version 1 ... EOD1 ... version 2 ... EOD2

On Fri, 23 Sep 2022 15:32:22 +1200, I wrote:
diff -u /dev/fd/8 /dev/fd/9 8<<EOD1 9<<EOD2
Just a note that this line might be better written as diff -u /dev/fd/8 /dev/fd/9 8<<'EOD1' 9<<'EOD2' Note the quotation marks: they disable special interpretation of “$” characters within the text. (Yes, I hit an example where I had some... <https://community.asterisk.org/t/strange-problem-on-rotary-french-phone/95431/3>)
participants (1)
-
Lawrence D'Oliveiro