提取两个模式(不包括模式)之间的文本 [英] Extract text between two patterns excluding patterns
本文介绍了提取两个模式(不包括模式)之间的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
考虑java -jar plantuml.jar -language
的输出:
;type
;26
abstract
actor
............................
;color
;147
AliceBlue
AntiqueWhite
Aqua
Aquamarine
............................
Wheat
White
WhiteSmoke
Yellow
YellowGreen
;EOF
我需要从此文本中提取颜色,而不能包含字符串.我已经阅读了几篇文章和《问答》,但没有找到答案.在这里,我找到了最合适的答案.
I need to extract colors from this text without surrounding strings. I have read several articles and Q&As and did not found answer. Here i found the most suitable answer.
$ java -jar plantuml.jar -language | sed -n '/\;color/,/\n\n/{/color/!{/\n\n/!p}}'
;147
AliceBlue
AntiqueWhite
Aqua
Aquamarine
Azure
Beige
Bisque
....................
Teal
Thistle
Tomato
Turquoise
Violet
Wheat
White
WhiteSmoke
Yellow
YellowGreen
;EOF
有一个细微的差别:;147
可以是任何其他值,而EOF
可以随时更改为其他值.我尝试了sed -n '/\;color\s*\;\d*/,/\n\n/
,但是它什么也没有返回.请帮助我获得下一个结果:
There is a small nuance: ;147
could be any other value and EOF
could be changed at any time to something other. I tried sed -n '/\;color\s*\;\d*/,/\n\n/
, but it returns nothing. Please help me to achieve the next result:
AliceBlue
AntiqueWhite
Aqua
Aquamarine
Azure
Beige
Bisque
....................
Teal
Thistle
Tomato
Turquoise
Violet
Wheat
White
WhiteSmoke
Yellow
YellowGreen
推荐答案
它听起来像您需要的所有声音:
It SOUNDS like all you need is:
awk '/^;/{if (/[[:alpha:]]/) f=(/color/?1:0); next} f'
这篇关于提取两个模式(不包括模式)之间的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文