我从cURL输出中获取以下数据。我只对data-key
和issue-link-summary
之后的数据感兴趣。请帮我解决一下这个。这是参考输出
<div class="aui-group split-view"><div class="aui-item list-results-panel"><div class="list-panel"><div class="list-ordering"></div><div class="list-content"><ol class="issue-list"><li data-id="95253" data-key="WXYZ-15288" title="b1-257-07.ch.abcde.com /grid/* 100%,"><a class="splitview-issue-link" data-issue-key="WXYZ-15288" href="/browse/WXYZ-15288"><img height="16" width="16" alt="Incident" title="Incident - " src="/secure/viewavatar?size=xsmall&avatarId=11100&avatarType=issuetype" /> <span class="issue-link-key">WXYZ-15288</span><br/><span class="issue-link-summary">b1-257-07.ch.abcde.com /grid/* 100%,</span></a></li><li data-id="95073" data-key="WXYZ-15238" title="restarting h4dn30.nm.abcde.com region server,"><a class="splitview-issue-link" data-issue-key="WXYZ-15238" href="/browse/WXYZ-15238"><img height="16" width="16" alt="Incident" title="Incident - " src="/secure/viewavatar?size=xsmall&avatarId=11100&avatarType=issuetype" /> <span class="issue-link-key">WXYZ-15238</span><br/><span class="issue-link-summary">restarting h4dn30.nm.abcde.com region server,</span></a></li><li data-id="95047" data-key="WXYZ-15230" title="Fwd: Alert: abcd-fgh-db1.nm.abcde.com/Mysql Uptime,"><a class="splitview-issue-link" data-issue-key="WXYZ-15230" href="/browse/WXYZ-15230"><img height="16" width="16" alt="Incident" title="Incident - " src="/secure/viewavatar?size=xsmall&avatarId=11100&avatarType=issuetype" /> <span class="issue-link-key">WXYZ-15230</span><br/><span class="issue-link-summary">Fwd: Alert: abcd-fgh-db1.nm.abcde.com/Mysql Uptime,</span></a></li><li data-id="94928" data-key="WXYZ-15194" title="Re: [CRITICAL ALERT! Reached Rule: XX_eml_slayer_label_production"><a class="splitview-issue-link" data-issue-key="WXYZ-15194" href="/browse/WXYZ-15194"><img height="16" width="16" alt="Incident" title="Incident - " src="/secure/viewavatar?size=xsmall&avatarId=11100&avatarType=issuetype" /> <span class="issue-link-key">WXYZ-15194</span><br/><span class="issue-link-summary">Re: [CRITICAL] ALERT! Reached Rule: XX_eml_slayer_label_production</span></a></li><li data-id="94925" data-key="WXYZ-15193" title="Re: [CRITICAL] ALERT! Breached Rule: Reached Rule: XX_eml_slayer_label_production"><a class="splitview-issue-link" data-issue-key="WXYZ-15193" href="/browse/WXYZ-15193"><img height="16" width="16" alt="Incident" title="Incident - " src="/secure/viewavatar?size=xsmall&avatarId=11100&avatarType=issuetype" /> <span class="issue-link-key">WXYZ-15193</span><br/><span class="issue-link-summary">Re: [CRITICAL] ALERT! Reached Rule: XX_eml_slayer_label_production</span></a></li></ol></div></div><div class="end-of-stable-message-container"></div><div class="aui-group pagination-view count-pagination"><div class="refresh-container aui-item"><a href="#" class="refresh-table" title="Refresh results">Refresh results</a></div><div class="pagination-container aui-item"><div class="pagination" data-displayable-total="5"></div></div></div></div><div class="aui-item detail-panel navigator-issue-only"><div></div></div></div>
请注意,整个输出显示在一行中。字段数可能会有所不同。
答案 0 :(得分:0)
这是一种方式:
awk -vRS="=" '/data-key/ {f=NR} f && NR==f+1 {print "data-key="$1}'
data-key="WXYZ-15288"
data-key="WXYZ-15238"
data-key="WXYZ-15230"
data-key="WXYZ-15194"
data-key="WXYZ-15193"
更新:
awk -vRS="[<>]" -F\" '/data-key.*title/ {print $4,$6}' file
WXYZ-15288 b1-257-07.ch.abcde.com /grid/* 100%,
WXYZ-15238 restarting h4dn30.nm.abcde.com region server,
WXYZ-15230 Fwd: Alert: abcd-fgh-db1.nm.abcde.com/Mysql Uptime,
WXYZ-15194 Re: [CRITICAL ALERT! Reached Rule: XX_eml_slayer_label_production
WXYZ-15193 Re: [CRITICAL] ALERT! Breached Rule: Reached Rule: XX_eml_slayer_label_production