Process Substitution
From Sfvlug
(Difference between revisions)
Line 3: | Line 3: | ||
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: | 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 file1 > file1.sorted |
- | sort file2 > file2.sorted | + | sort file2 > file2.sorted |
- | diff file1.sorted file2.sorted | + | diff file1.sorted file2.sorted |
With process substitution, you can do this in a single line: | With process substitution, you can do this in a single line: | ||
- | diff <( sort file1 ) <( sort file2 ) | + | diff <( sort file1 ) <( sort file2 ) |
The "<(" is a token, so there must be no space between the characters, just like "$(" for variable substitution. | The "<(" is a token, so there must be no space between the characters, just like "$(" for variable substitution. |
Current revision as of 00:32, 5 December 2006
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.