bash - Print lines after a pattern until second occurrence of a different pattern -
so know how print lines 1 pattern pattern:
sed -ne '/pattern_1/,/pattern_2/ p'
which works input looks this:
random_line_1 pattern_1 random_line_2 random_line_3 random_line_4 random_line_5 pattern_2 random_line_6
so lines pattern_1
pattern_2
printed.
but how can print lines until second occurrence of second pattern:
random_line_1 pattern_1 pattern_2 random_line_3 random_line_4 random_line_5 pattern_2 random_line_6
i want print lines pattern_1
second pattern_2
output:
pattern_1 pattern_2 random_line_3 random_line_4 random_line_5 pattern_2
more specifically, trying capture text, starting @ header, surrounded empty lines, may or may not have text before header , after second empty line (where pattern_1
header , pattern_2
empty line):
header: <empty line> some_text some_more_text even_more_text when_will_it_stop <empty line>
preferably, sed
answer work best since know little bit how works, open awk
submissions, long every piece of command explained.
a simpler sed example specific case:
sed -ne '/pattern_1/,/pattern_2/{/pattern_1/n;p}'
this says within range, suck line after header pattern_1
pattern space , print it. means if line after pattern_1
pattern_2
, occurence of pattern_2
not count range.
in other words: sed -ne '/header/,/^$/{/header/n;p}'
Comments
Post a Comment