0

I would like to write some filtered output of a given command (rsync) into a file but keep the complete unfiltered output on stdout (the screen/terminal).

I've tried some combinations of sed, tee & process substitution but cannot make this work.

Here's what I've got so far:

rsync -aAXz --stats -v src dest > >(sed '0,/^$/d' | tee -a "summary.log")

sed '0,/^$/d' deletes everything before the first blank line which leaves rsync's summary and deletes the leading verbose output. This is working as expected and only prints the summary to summary.log.

Obviously it also deletes the verbose output from stdout since the tee command only receives the filtered sed output over the pipe.

How can I write to stdout before filtering with sed to see all the verbose output on the screen/terminal?

suamikim
  • 5,350
  • 9
  • 40
  • 75

1 Answers1

0

To write your complete output from stdout to the log file, do that first (using tee), and then deal with the terminal. Something like this:

rsync -aAXz --stats -v src dest | tee -a "summary.log" | sed '0,/^$/d'

That "splits" or duplicates the output stream, with one copy of the complete stream being diverted by tee to the output log, and another copy being sent to its stdout, which becomes the input to sed....

gilez
  • 669
  • 3
  • 6