【问题标题】:To extract sub-part of string in shell script [duplicate]在shell脚本中提取字符串的子部分[重复]
【发布时间】:2020-03-27 21:39:27
【问题描述】:

我有日志文件,其中每一行都显示警告

17>C:\Work\gital\DK\GK\astl/algorithm.h(1186): 警告 C4389: '==' : 有符号/无符号不匹配 (C:\Ga\门\源\src\MainSc.cpp)

17>C:\Work\gital\DK\GK\dgfgtl/string.h(1084): 警告 C4127: 条件表达式是常数 (C:\Ga\gate\source\src \FreeSc.cpp)

从每一行,我想得到字符串的一部分

algorithm.h(1186):警告 C4389:'==':有符号/无符号不匹配 MainSc.cpp

string.h(1084): 警告 C4127: 条件表达式是常量 FreeSc.cpp

如果我能得到这些提取,那就太好了。基本上我有带有警告数据的日志文件,我想从中提取子部分。

【问题讨论】:

    标签: bash shell extract


    【解决方案1】:

    对于给定的 2 行,cut 是最简单的答案。根据其他行,您可能想要其他东西:

    cut -d/ -f2 logfile
    grep -Eo "/.*" logfile
    sed 's/.*astl.//' logfile
    

    【讨论】:

    • 我的错,我们可能没有“astl”字符串,它可能是任何东西
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-09-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-12
    • 1970-01-01
    • 2015-10-20
    相关资源
    最近更新 更多