1

我有以下 xml

## 13 Aug 2013 14:53:44, 390 [INFO] OrderId 100 otherInfo
<someXML>details
<info>details<info>
<info1>details<info1>
</someXML>
## 13 Aug 2013 14:53:44, 390 [INFO] OrderId 105 otherInfo
<someXML>details
<info>details<info>
<info1>details<info1>
</someXML>
## 13 Aug 2013 14:55:45, 490 [INFO] OrderId 100 otherInfo  
<someXML>details
<info>details<info>
<info1>details<info1>
</someXML>
## 13 Aug 2013 14:53:44, 390 [INFO] OrderId 105 otherInfo
<someXML>details
<info>details<info>
<info1>details<info1>
</someXML>

我想用 orderid "example OrderId 100" 搜索特定行并打印该行及其下方的所有内容,直到下一个以 doulbe hash(##) 开头的订单行,所以如果我使用 orderid 100 搜索,我应该得到以下

## 13 Aug 2013 14:53:44, 390 [INFO] OrderId 100 otherInfo
<someXML>details
<info>details<info>
<info1>details<info1>
</someXML>
## 13 Aug 2013 14:55:45, 490 [INFO] OrderId 100 otherInfo 
<someXML>details
<info>details<info>
<info1>details<info1>
</someXML>
4

2 回答 2

2

您的记录很好地分开,因此将记录分隔符设置为##并搜索OrderId您想要的:

$ awk '/OrderId 100/{print RS $0}' RS='##' ORS=''  file
## 13 Aug 2013 14:53:44, 390 [INFO] OrderId 100 otherInfo
<someXML>details
<info>details<info>
<info1>details<info1>
</someXML>
## 13 Aug 2013 14:55:45, 490 [INFO] OrderId 100 otherInfo
<someXML>details
<info>details<info>
<info1>details<info1>
</someXML>
于 2013-08-13T07:57:36.087 回答
0

这可能对您有用(GNU sed):

sed '/OrderId 100/!d;:a;$!{n;/^##/{s/^/\n/;D};ba}' file
于 2013-08-13T09:40:57.363 回答