Home > OS >  Full redirect to a log file but remove, on the fly, some text from log
Full redirect to a log file but remove, on the fly, some text from log

Time:04-13

I'm having this code in bash

function main() {
  code here
  echo "data is here"
  code here
  echo "new data is here"
  echo "sensitive data"
  code here
  echo "another data here"
}

main |& tee -a logFile

The problem is that I want to remove [ or not to send if possible ] the "sensitive data" from the log

I tried with sed but if I'll change the logFile on the fly, the new data will not be appended anymore

Any ideas?

CodePudding user response:

The easiest way would be to modify your main function and write the sensible data directly to the terminal:

function main() {
    # ...
    echo "sensitive data" > /dev/tty
    # ...
}

An other possibility would be to insert an awk script in the pipe, in between main and tee, for "redirecting" the sensible lines to /dev/stderr or /dev/tty:

main |& awk '/sensible data/ { print > "/dev/tty"; next } 1' | tee -a logFile

edit: added quotes to /dev/tty for making it work with other awks that the GNU one.

  •  Tags:  
  • bash
  • Related