Reputation: 8221
Consider the output of 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
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
Upvotes: 0
Views: 245
Reputation: 15461
With sed to delete all lines between patterns not starting with ;
:
sed -n '/^;color/,/^;EOF/{/;/d;p}' file
To delete last blank line:
sed -n '/^;color/,/^;EOF/{/;/d;/^$/d;p}' file
or with GNU sed:
sed -n '/^;color/,/^;EOF/{/^;\|^$/d;p}' file
Upvotes: 1
Reputation: 204488
It SOUNDS like all you need is:
awk '/^;/{if (/[[:alpha:]]/) f=(/color/?1:0); next} f'
Upvotes: 2