I am attempting to run a Linux command such as nmap & pass the input into the txt2html command which then appends to a file but also show the output of the nmap command only. The command provided works, but it outputs the txt2html output and I just want the nmap output to show on the terminal. Is there a way to do this?

nmap localhost | txt2html -extract -8 | tee -a file_to_append

2 Answers 2


I believe this is what you want:

nmap localhost | tee /dev/stderr | txt2html -extract -8 >> file_to_append


  1. You run nmap
  2. The output of nmap is sent both file /dev/stderr (which is just standard error) and also stdout
  3. txt2html reads the previous steps stdout and appends its output to file_to_append Now stderror was never redirected so it would should appear in your console for you to see.

Here is an example without output with some dummy commands

$ echo hi | tee /dev/stderr | sed "s/hi/bye/" > /tmp/test.txt
$ cat /tmp/test.txt

You can see the terminal output and the saved contents differ

  • Ahh worked like a charm, thank you so much!
    – E-Guy
    Jul 29, 2022 at 20:42

Assuming that you are using a shell that supports process substitutions with >(...), then you could use tee to redirect into the txt2html command for you:

nmap localhost | tee >(txt2html -extract -8 >>some-file)

Here, txt2html gets its input from tee and appends its output to some-file.

Apart from writing to txt2html, tee would also write its original input to the standard output stream, which presumably would be connected to the terminal.

In this scenario, any diagnostic output from nmap would bypass both tee and txt2html and be sent directly to the terminal. If you instead want to process this, redirect the output of the command on the left-hand side of the pipeline with 2>&1 so that its standard error stream is redirected along with the standard output stream.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .