-2

Redirect the output to two different files, One should have new output whenever the commands execute and the other should have both new & old content.

For example:

 openstack port create --network testnetwork1 test1-subport110 --disable-port-security --no-security-group 

I need to redirect output into 2 different file. File A.txt and B.txt. Whenever executed the openstack port create command the new output should be in A.txt and old & new output should be in B.txt.

I want like below,

cat A.txt
port2UUID

cat B.txt port1.UUID port2.UUID

Kindly help me. Thanks in advance

Beginner
  • 1,960

1 Answers1

4
cmd | tee A.txt >> B.txt

Or

cmd | tee -a B.txt > A.txt

Would tee (think of a plumber's T) cmd's output both into A.txt and in append mode into B.txt.

With the zsh shell, you can also do:

cmd > A.txt >> B.txt

(where zsh does the T'ing internally by itself when redirecting the same file descriptor several times).


To include cmd's stderr into the inflow of the T, use:

cmd 2>&1 | tee A.txt >> B.txt

Or in zsh:

cmd > A.txt >> B.txt 2>&1

Or:

cmd >& A.txt >>& B.txt