小编use*_*005的帖子

包含方括号的 Grep 字符串

这是数据

10:43:19.538281|TraceDetail    |UPBSStandardGenericBillPaymentComponent.PostBillPaymentTransaction|Total Time    19/06/2019 10:43:19.538281|TraceDetail    |UPBSStandardGenericBillInquiryComponent.GetBillInquiry()|Total Time                    |2361748             | Consumer Number [0312122221212             ] , UCID [KLOJ0001] ,  Sending Time [10:43:17.8425459] Receive Time [10:43:18.4941158] Total Time [0:0:651] STAN is [345949]
Run Code Online (Sandbox Code Playgroud)

我要输出

[0312122221212             ]
[KLOJ0001]
[10:43:17.8425459]
[10:43:18.4941158]
[0:0:651]
[345949]
Run Code Online (Sandbox Code Playgroud)

我尝试了很多命令,但无法使用以下命令实现结果:

grep -oP 'Consumer Number \K.{26}|UCID \K.{10} |Sending Time \K.{09}|Receive Time \K.{09}|Total Time \\[ \K.{8}|STAN is \K.{8}' /root/Documents/a.txt
Run Code Online (Sandbox Code Playgroud)

我得到了没有总时间的输出:

[0312122221212             ]
[KLOJ0001]
[10:43:17.8425459]
[10:43:18.4941158]
[345949]
Run Code Online (Sandbox Code Playgroud)

当我尝试这个命令时:

grep -oP 'Consumer Number \K.{26}|UCID \K.{10} |Sending Time \K.{09}|Receive Time \K.{09}|Total Time \K.{8}|STAN is \K.{8}' /root/Documents/a.txt …
Run Code Online (Sandbox Code Playgroud)

grep regular-expression

6
推荐指数
1
解决办法
1万
查看次数

标签 统计

grep ×1

regular-expression ×1