Say I have this as input:
..pattern1...this
..pattern1...1
..pattern1...2
...
Or
..pattern1...0
..pattern2...0
..pattern1...1
..pattern2...1
..pattern2...2
..pattern1...this
...
I.e. list of lines containing only two types of patterns (strings).
I'm trying to obtain the first line of pattern1
after the last line of pattern2
. If there is no pattern2
then the first line of pattern1
.
Example output for both cases would be:
..pattern1...this
I can do either one of this cases separately with sed
(like with this answer) but I wasn't able to get a command which would do both ad the same time.
Anyone can jump in and lend an hand? Thanks!