2014-10-19 It is usually harmful to try to write into the same file from which is read in a pipeline. This heavily fails if you do output redirection (because the shell truncates the file before any com- mand can read from it). But a try like this one will only by chance work as expected: uniq test.txt | tee test.txt # Do not use this! It might work in the case when all input fits in one buffer, be- cause then the data gets ... uhm, buffered. What you can use is: sort -o foo foo The reason is that sort have to read all input before it is able to output. (You still cannot use any output redirection, because that would be done by the shell *before* the command gets in- voked.) [0] Another nice problem I came across today: [1] Search for a line matching some regexp, nine lines further down from there, replace `foo' with `bar'. What a wonderful task for ed. :-) ed - file <