Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Avoid temp file in bash command

Tags:

linux

bash

I'm trying to avoid the creation of a temp file (in the example t12.txt) using some bash tricks, to no avail.

Suppose two files t1.txt and t2.txt, with some text lines.

Example of a command working:

$ cat t1.txt t2.txt > t12.txt
$ tac t2.txt t1.txt | tac | diff - t12.txt

Now I'm trying to avoid the creation of t12.txt using anything, from pipes to weird redirects.

Commands I tried in different orders and tests are things like: $(cat t1.txt t2.txt) or < <(cat t1.txt t2.txt).

Any creative suggestion here? Ty.

like image 729
DrBeco Avatar asked Aug 22 '15 15:08

DrBeco


1 Answers

This should do the job:

diff <(cat t1.txt t2.txt) <(tac t2.txt t1.txt)

This just creates temporary file descriptors at /dev/fd for the outputs of cat t1.txt t2.txt and tac t2.txt t1.txt respectively.

like image 120
Siguza Avatar answered Sep 28 '22 09:09

Siguza