2013-12-12 55 views
1

我想在输出中出现logically moving media as follows...后打印行。注意:这个特定的模式可以发生在文件的任何地方。如何在模式匹配后打印所有行

请让我知道我该怎么做到这一点?

下面是我的文件:

Generating list of recommended changes ... 

Proposed Change(s) to Update the Volume Configuration 
===================================================== 
Logically move media ID PN0960 (barcode PN0960L4) from standalone to slot 18. 
Logically move media ID PN1067 (barcode PN1067L4) from standalone to slot 44. 
Logically move media ID PN1080 (barcode PN1080L4) from standalone to slot 52. 
Logically move media ID PN1711 (barcode PN1711L4) from standalone to slot 54. 
Logically move media ID PN1728 (barcode PN1728L4) from standalone to slot 109. 
Logically move media ID PN1926 (barcode PN1926L4) from standalone to slot 112. 
Logically move media ID PN1933 (barcode PN1933L4) from standalone to slot 134. 
Logically move media ID NY2617 (barcode NY2617L4) from standalone to slot 165. 
Logically move media ID PN0016 (barcode PN0016L4) from standalone to slot 167. 
Logically move media ID NY2011 (barcode NY2011L4) from standalone to slot 186. 
Logically move media ID NY2021 (barcode NY2021L4) from standalone to slot 203. 
Logically move media ID NY2046 (barcode NY2046L4) from standalone to slot 262. 
Logically move media ID NY2222 (barcode NY2222L4) from standalone to slot 376. 
Logically move media ID NY2236 (barcode NY2236L4) from standalone to slot 377. 
Logically move media ID NY2290 (barcode NY2290L4) from standalone to slot 385. 
Logically move media ID NY2519 (barcode NY2519L4) from standalone to slot 485. 
Logically move media ID NY2017 (barcode NY2017L4) from standalone to slot 487. 
Logically move media ID NY2048 (barcode NY2048L4) from standalone to slot 490. 
Logically move media ID NY2133 (barcode NY2133L4) from standalone to slot 494. 
Logically move media ID NY2135 (barcode NY2135L4) from standalone to slot 495. 
Logically move media ID NY2149 (barcode NY2149L4) from standalone to slot 496. 
Logically move media ID NY2348 (barcode NY2348L4) from standalone to slot 497. 
Logically move media ID NY2371 (barcode NY2371L4) from standalone to slot 498. 
Updating volume configuration ... 

Processing existing media added to or moved within the robotic library by 
logically moving media as follows... 
     Media ID  Slot 
     ========  ==== 
     PN0960   18 
     PN1067   44 
     PN1080   52 
     PN1711   54 
     PN1728   109 
     PN1926   112 
     PN1933   134 
     NY2617   165 
     PN0016   167 
     NY2011   186 
     NY2021   203 
     NY2046   262 
     NY2222   376 
     NY2236   377 
     NY2290   385 
     NY2519   485 
     NY2017   487 
     NY2048   490 
     NY2133   494 
     NY2135   495 
     NY2149   496 
     NY2348   497 
     NY2371   498 


Volume configuration successfully updated. 

回答

2

awk是途径之一:

$ awk '/logically moving media as follows/ {p=1} p' file 

它看起来为"logically moving media as follows"文本。一旦找到,标志p被激活{p=1}。最后的p条件是真的,所以执行awk的默认行为,即{print $0}

它返回:

logically moving media as follows... 
     Media ID  Slot 
     ========  ==== 
     PN0960   18 
     PN1067   44 
     PN1080   52 
     PN1711   54 
     PN1728   109 
     PN1926   112 
     PN1933   134 
     NY2617   165 
     PN0016   167 
     NY2011   186 
     NY2021   203 
     NY2046   262 
     NY2222   376 
     NY2236   377 
     NY2290   385 
     NY2519   485 
     NY2017   487 
     NY2048   490 
     NY2133   494 
     NY2135   495 
     NY2149   496 
     NY2348   497 
     NY2371   498 


Volume configuration successfully updated. 
3

或者与

sed -n '/logically moving media as follows/,$p' input.txt 

这将打印匹配logically moving media as follows直到文档结束的所有行。

2

使用fedorqui的溶液或:

sed -rn '/logically moving media as follows/,$p' file 
相关问题