【发布时间】:2021-12-17 20:23:01
【问题描述】:
我正在尝试抑制 bash 中命令的 一些 输出,这与 suppressing all output 不同,因为大多数输出都是有用的,除了几行重复数百次我想忽略。
用例:我有一个 CI 服务器,在构建过程中的某个时间点,我发布了一个 dotnet lambda 函数:
dotnet lambda package {...}
除了来自here 和there 的几个记录器调用之外,大多数日志输出都很有用。没有办法通过命令行切换到命令本身来抑制这些,这使得我的构建日志比我想要的要大得多:
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]
仅当行包含Changed permissions on published file 或zipping 时,我想禁止输出到标准输出。我该怎么做?
【问题讨论】:
-
您可以使用 grep 隐藏包含一些文本的行;
./showoutput.sh | grep -v 'Changed permissions on published file' -
一般的方法是通过其他程序过滤掉不需要的数据。您仅给出了不需要的行的示例,没有一般规则。根据要求,过滤过程可能只是对
grep的调用,或者是用awk 或Ruby 之类的东西编写的小程序。