使用Shell从服务器日志中提取ID?

时间:2020-05-14 22:44:56

标签: regex awk sed

在具有如此合理的分隔符的文件中,我多次重复以下blob:

“ 2020-05-12T07:51:56,071Z致命[] [消息=无法处理事件xyz :: 5bf0726d-5927-32d0-92b3-5c741d9c15ec:ID的关联失败xyz :: 5bf0726d-5927- 32d0-92b3-5c741d9c15ec,部分(服务:AmazonDynamoDBv2;状态代码:400;错误代码:ValidationException;请求ID:))... splunkcloud.com,

类似.. .other-content { height: 240px; background-color: gray; } .other-content .nav { position: sticky; top: 0; font-weight: 800; } .container { display: flex; } .left, .right { width: 50%; border: 1px red solid; } .left { height: 600px; background-color: lightblue; } .right { background-color: purple; } .bottom-attached { background-color: yellow; position: sticky; bottom: 0; }

我特别想从此日志中提取ID <div class='other-content'> <span>product info....</span> <div class='nav'>A cool sticky nabar - THIS WORKS!</div> </div> <div class='container'> <div class='left'></div> <div class='right'> <div class='bottom-attached'>I want this to be attached to the bottom of the screen within the purple `div` as you scroll down.</div> </div> </div>(该ID不断重复。该值可以以字母数字结尾,并且始终以(xyz::[0-9A-Za-z-]+)开头。

我最终希望将文件放入外壳并通过awk / sed之类的文件运行,因此我只能使用这些ID的行分隔文件。谢谢。

1 个答案:

答案 0 :(得分:2)

您可以使用grep

grep -o 'xyz::[[:xdigit:]]\{8\}\(-[[:xdigit:]]\{4\}\)\{3\}-[[:xdigit:]]\{12\}' file

[:xdigit:]是与a-fA-F0-9字符匹配的POSIX字符类。 \{8\}匹配八次出现。 \(-[[:xdigit:]]\{4\}\)\{3\}匹配三个-连字符块,后跟4个数字字符。匹配以-和12个数字字符结尾。