尝试从文本文件中grep实例id

时间:2016-06-06 20:17:56

标签: linux bash shell grep sh

我有一个文本文件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.

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

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

它不起作用。请建议正确的方法。

1 个答案:

答案 0 :(得分:2)

试试这个grep

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