Overview
Consider an ordered list interspersed with unordered elements, e.g.:
Alligator
Ant
Falcon <--
Baboon
Badger
Armadillo <--
Caiman
Cat
How can this list be processed so that all unordered elements are deleted? E.g.:
Alligator
Ant
Baboon
Badger
Caiman
Cat
Some more information
The unordered elements are always singular, the ordered elements come in groups of at least 2 lines. The general pattern would be:
ordered
ordered
ordered
unordered <--
ordered
ordered
unordered <--
ordered
ordered
The unordered elements can be both lower…
A
B
F <---
D
E
…and higher than the following ordered element:
A
C
B <---
D
E
To make matters even more difficult: The elements can be both upper- and lowercase and contain diacritics (e.g.: ä,ö,à).
Is there any way to accomplish this with bash?
Best Answer
This works if the last line is OK:
old version (with bugs, for comparison)