【问题标题】:delete letter in the output linux删除输出linux中的字母
【发布时间】:2013-12-31 05:48:54
【问题描述】:

我在 linux 中有以下文本作为输出:

    service {'name': 'services'}
    enable yes
    frequency 7200
    service {'name': 'files'}
    enable yes
    frequency 6000
    none

我正在寻找将输出转换为以下内容的方法:

services yes 7200
files yes 6000

我正在使用下一个命令:

| xargs -n 7 | awk '{print $3 " / " $5" / " $7}'

但作为输出我有:

services} / yes / 7200
files} / yes / 6000

无论如何要删除那个},或者得到没有这个字符的最后一个输出?

【问题讨论】:

    标签: linux shell output


    【解决方案1】:

    如果您可以删除任何和所有 '}',最简单的方法是使用 translate:

    | xargs -n 7 | awk '{print $3 " / " $5" / " $7}'| tr -d '{'
    

    tr -d 将删除'{'的每个实例

    【讨论】:

      【解决方案2】:

      如果您将字段分隔符设置为除字母和数字之外的任何内容,它会简化解析:

      awk -F'[^a-z0-9]+' '
          /service/ {printf "%s ", $3}
          /enable/ {printf "%s ", $2}
          /frequency/ {print $2}
      ' /tmp/test-data
      

      输出:

      services yes 7200
      files yes 6000
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-02-04
        • 1970-01-01
        • 2019-10-04
        • 2014-11-12
        • 2020-02-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多