【问题标题】:Multiple inputs in one command一个命令中的多个输入
【发布时间】:2017-03-27 22:13:48
【问题描述】:

我有这样的东西:

错误代码=1;数=5;

错误代码=2;数=7;

错误代码=3;数=9;

错误代码=1;数=2;

错误代码=2;数=5;

。 . .

还有很多错误代码(大约 100 个) 假装名为 performance.log 的文件

我如何使用一个命令,但每次错误代码都不同 喜欢:

grep -i "error_code=$x;" performance.log | awk -F";" '{print $2}' > $x_error_code.txt

所以每次变量 x 都是从错误代码定义的新值 当错误代码完成时,脚本将完成

【问题讨论】:

  • 你已经尝试过什么?最好提出具体问题而不是一般性建议。
  • 你期待什么结果?
  • @RomanPerekhrest 文件中的每个错误代码

标签: unix printing grep multiple-value


【解决方案1】:

将输入文件拆分为每个错误代码的单独文件:

awk -F";" '{fn=substr($1, index($1,"=")+1); print $2 > fn"_error_code.txt";}' performance.log

【讨论】:

    猜你喜欢
    • 2019-05-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-13
    • 1970-01-01
    • 1970-01-01
    • 2012-08-08
    相关资源
    最近更新 更多