【问题标题】:Trying to grep instance id from within a text file尝试从文本文件中 grep 实例 ID
【发布时间】:2016-10-06 13:50:14
【问题描述】:

我有一个文本文件bak.txt,内容如下:

^[[34mINFO^[[0m[0000] Your engine version 1.11.1-cs1 is compatible
^[[34mINFO^[[0m[0000] We detected local components of UCP instance H7LQ:WKR5:G2PX:4F3V:JQ47:WCIG:JV4W:V6SE:4WMR:TLZN:XYWH:MIEQ
^[[31mFATA^[[0m[0000] Re-run the command with "--id H7LQ:WKR5:G2PX:4F3V:JQ47:WCIG:JV4W:V6SE:4WMR:TLZN:XYWH:MIEQ" or --interactive to confirm you want to upgrade this UCP instance.

我现在正在尝试使用以下命令从 bak.txt 文件中 grep UCP instance 值:

grep -Po '(?<=instance=)[^"]*' bak.txt

它不工作。请提出正确的方法。

【问题讨论】:

    标签: linux bash shell grep sh


    【解决方案1】:

    试试这个grep:

    grep -oP '(?<=instance )[^"]+' bak.txt
    

    【讨论】:

    • 我试过了,但它给出了一个空行。请建议
    • @mealhour 你做错了,anubhava 的正则表达式是正确的。
    • 似乎输出是黑色墨水而不是白色墨水。我可能还需要设置color 选项
    • 试试:grep --color -oP '(?&lt;=instance )[^"]+' bak.txt
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-27
    • 2021-06-01
    • 2012-07-17
    • 2012-04-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多