Process Substitution

From Sfvlug

Here is a quick tip on a way to use process substitution. I'll try to add more later.

If you have two files, each with an unordered list of information, and you want to see what is unique to one file or the other, you might be tempted to do the following:

sort file1 > file1.sorted
sort file2 > file2.sorted
diff file1.sorted file2.sorted

With process substitution, you can do this in a single line:

diff <( sort file1 ) <( sort file2 )

The "<(" is a token, so there must be no space between the characters, just like "$(" for variable substitution.

Personal tools