Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grepping Make Output

Tags:

grep

makefile

When trying to filter very long output from make for specific warnings or error messages, the first idea would be something like this:

$ make | grep -i 'warning: someone set up us the bomb'

The result is not fully satisfying, though. The output will not just contain the filter results from grep but also stdout and stderr messages from other tools that are used in the make target somewhere.

The question now is:

  1. Where does the other output come from?
  2. How to write the filter command that the output will only contain the filtered lines?
like image 263
erikbstack Avatar asked Sep 18 '13 13:09

erikbstack


1 Answers

To answer the questions:

  1. The pipe only connects the stdout of make to the stdin of grep. make's stderr is still connected to the terminal in will therefore be printed without filtering.
  2. The solution is connect make's stderr to its stdin and ignore the stdin

    $ make 2>&1 >/dev/null | grep -i 'warning: someone set up us the bomb'
    

This only prints the output of grep, but nothing from make or other tools like rm.

like image 53
erikbstack Avatar answered Nov 08 '22 19:11

erikbstack