0

I am trying to suppress some output from a command in bash, this is different to suppressing all output, because most of the output is useful, apart from a few lines that repeat hundreds of times which I would like to ignore.

Use-case: I have a CI server, at some point during the build, I am publishing a dotnet lambda function:

dotnet lambda package {...}

Most log output is useful, apart from a couple of logger calls from here and there. There is no way to suppress those via command-line switches to the command itself, which makes my build log much larger than I would like it to be:

48.67 ... publish:   FooBar.Client -> {...}/FooBar.Client.dll          <<< Useful
49.29 ... publish:   FooBar -> {...}/bootstrap.dll
49.71 ... publish:   FooBar -> {...}/publish/
49.73 Changed permissions on published file (chmod +rx appsettings.json). <<< Meh
      [Repeated many times for other files]
#12 49.91 ... zipping:   adding: appsettings.json (deflated 29%)          <<< Meh
      [Repeated many times for other files]

I would like to suppress output to standard out only if the line contains Changed permissions on published file or zipping. How do I do it?

2
  • You can use grep to hide lines containing some text; ./showoutput.sh | grep -v 'Changed permissions on published file' Commented Nov 3, 2021 at 12:57
  • The general approach is that you pipe it through some other program which filters out the unwanted data. You gave only examples on what lines are unwanted, no general rule. Depending on the requirements, the filtering process could be just an invocation of grep, or a small program written in something like awk or Ruby. Commented Nov 3, 2021 at 13:18

1 Answer 1

4

You can use grep -v to filter out lines on stdout containing the two search strings while printing all the rest. This does that and leaves stderr alone:

dotnet lambda package {...} | grep -v -e 'Changed permissions on published file' -e 'zipping'

You may also want to add --line-buffered to tell grep to print lines immediately and not buffer its output. This can be helpful if you're trying to view the log in realtime, but if the log is just going to disk to be viewed later I wouldn't use it since it'll make grep a little bit slower.

dotnet lambda package {...} | grep -v --line-buffered -e 'Changed permissions on published file' -e 'zipping'
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.