Suppose I am executing a script like this:

/a/b/c/script.sh >> abc.log

This means that all the contents/execution of script will be re-directed to abc.log. If I want a particular line inside the script not to be re-directed to abc.log, then how do I do that?

closed as unclear what you're asking by Braiam, dhag, roaima, Anthon, Jander Jul 16 '15 at 15:04

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 4
    How will you identify the line that you do not want? By line number? By regex? – Eric Renouf Jul 16 '15 at 13:08
  • Typically you would sent the output you don't want to go to stdout, to stderr. – Anthon Jul 16 '15 at 14:51
/a/b/c/script.sh >> abc.log

This command means that any output that script.sh writes to the standard output stream will be appended to abc.log

If you wish to exclude a line, or multiple lines that match a similar pattern you can use grep -v to accomplish this:

/a/b/c/script.sh | grep -v '<line-to-ignore>' >> abc.log

or to match a pattern (e.g. all lines that start with the word cat):

/a/b/c/script.sh | grep -vE '^cat' >> abc.log

The -v flag to grep means to invert the match, so any lines that match the pattern you supply will be filtered out.


You can use a tool like sed to alter the output of script.sh, including "deleting" lines from the stream. If you want to delete a line by line number you could do

/a/b/c/script.sh | sed -e '5d' >> abc.log

which in this example will remove the 5th line from the output. Replace 5 with any line number.

/a/b/c/script.sh | sed -e '/<regex>/d' >> abc.log

will remove any line that matches the regex from the output.


You don't get to select lines. Only whole streams (stdin, stdout, stderr (more generally, any open file descriptors, not just these standard ones)) can be redirected.

You can simulate what you want by piping into commands that will sort out the output lines for you.

$ echo -e "hello\nworld"   |  #write hello and world; one per line
tee >(grep hello >1.log) |  #select line matching hello and write it to 1.log
grep -v hello > 2.log  #select lines NOT matching hello and write them to 2.log

If it is a specific line/command in the script, you can send its output to /dev/null inside the script. The command inside the script will look like:

command > /dev/null

This will result in the output getting lost. If you want it to appear on the console, you can send it to stderr as

command 2> `tty` 1>&2

Not the answer you're looking for? Browse other questions tagged or ask your own question.