Filter command output using grep

I have a command line program that I am using, which logs to the console. However, do to some buggy firmware, it prints a certain error every 1 seconds.

How can I use grep to filter the output so that this one specific error line is omitted from being logged to the console?

The exact error I want to get rid of is:

[1] [NTC] [NET] netcam_read_html_jpeg: Potential split boundary - 1447 chars flushed, 1 re-positioned

If I create an sh script with the offending line in it, like so:

#!/bin/sh

echo "[1] [NTC] [NET] netcam_read_html_jpeg: Potential split boundary - 1447 chars flushed, 1 re-positioned"
echo "testing"

And then run it, the output is, as expected,

[1] [NTC] [NET] netcam_read_html_jpeg: Potential split boundary - 1447 chars flushed, 1 re-positioned
testing

Now, if I run it using grep -v to try to omit this line, like so:

./script.sh | grep -v "[1] [NTC] [NET] netcam_read_html_jpeg: Potential split boundary - 1447 chars flushed, 1 re-positioned"

The output is still:

[1] [NTC] [NET] netcam_read_html_jpeg: Potential split boundary - 1447 chars flushed, 1 re-positioned
testing

However, if I run the same script, this time trying to get rid of the line containing testing, like so:

./script.sh | grep -v "testing"

Then the output is, as expected:

[1] [NTC] [NET] netcam_read_html_jpeg: Potential split boundary - 1447 chars flushed, 1 re-positioned

Now what's wrong here?? Clearly, I am using the right command, since it works in the second example. It just doesn't work to omit the actual line I want it to!

What am I missing?

Upvotes: 2

Views: 2469

Answers (1)

I got it!

The lines printing to the console were being sent on stderr, so grep wasn't even looking at anything.

The command I ran to make it work was:

sudo motion 2> >(grep -v "\[1\] \[NTC\] \[NET\] netcam_read_html_jpeg: Potential split boundary - 1447 chars flushed, 1 re-positioned" 1>&2)

Upvotes: 2

Related Questions