I'd like to compare the output of one program on two files. It would be something like:
comm -23 <(cat a/somefile) <(cat b/somefile)
Where cat
is a stand in for a monster of a command.
Here's what I know. If I do echo {a,b}/somefile
then I get
a/somefile b/somefile
which is correct.
I tried to apply this "explosion" to the process substitution: comm -23 <(cat {a,b}/somefile)
needless to say I got an error comm: missing operand after ‘/proc/self/fd/16’
. Is this possible to do?
CodePudding user response:
The {a,b}
syntax is a form of brace expansion, but its scope is limited. It won't repeat everything to the left of it:
$ echo cat {a,b}/somefile
cat a/somefile b/somefile
However, if the there's anything "touching" the left brace:
$ echo cat{a,b}/somefile
cata/somefile catb/somefile
Going back to your example, the <(cat {a,b}/somefile)
part expands to <(cat a/somefile b/somefile)
, which will just concatenate the contents of the two files and put them into the temp file created by the process substitution. But comm
expects two arguments, not one, which is why you're getting the error. You knew this, but I guess you had different expectations about how brace expansion behaves (the scope up to which it extends).
I suggest you just create your own function with that "monster of a command" and reuse it in two process substitutions:
monster() {
cat "$@"
}
comm -23 <(monster a/somefile) <(monster b/somefile)