【问题标题】:remove string after [ character using shell script? [duplicate]使用shell脚本删除[字符后的字符串? [复制]
【发布时间】:2018-04-05 17:34:29
【问题描述】:

我有一个包含如下字符串的文件: ./intercompany.rb[1:1] |通过 | 9分7秒|

我想删除 [ 字符之后的字符串。 输出应该是 ./intercompany.rb

我们如何在 shell 脚本中做到这一点?

【问题讨论】:

    标签: shell


    【解决方案1】:
    s='./intercompany.rb[1:1] | passed | 9 minutes 7 seconds |'
    echo "${s%%[*}"
    

    请参阅http://wiki.bash-hackers.org/syntax/pe 和/或BashFAQ #100

    【讨论】:

      【解决方案2】:

      sed:

      sed 's/\[.*//' < file
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-11-14
        • 2016-04-12
        • 2012-12-21
        • 2013-10-20
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多