sort words per section

I have this text file that I need to sort per section.

#cat raw_file.txt

== other info ==
===instructions===
===english words===
this
is
only
test


=== missing words ===

==== include words ====
some
more
words

==== customer name ====
ram
sham
amar
akbar
anthony

==== cities ====
mumbai
delhi
pune


=== prefix ===

the
a
an

If I sort it "as is" then it starts with 2 equal signs followed by 3 equal signs and then all the words. How do I sort the words per section separately?

# sort raw_file.txt

== other info ==
=== missing words ===
=== prefix ===
==== cities ====
==== customer name ====
==== include words ====
===english words===
===instructions===
a
akbar
amar
an
anthony
delhi
is
more
mumbai
only
pune
ram
sham
some
test
the
this
words

This is mediawiki format if that matters. I am sorting each and every section and that is taking a lot of time.

#cat expected_output.txt

== other info ==
===instructions===
===english words===
is
only
test
this

=== missing words ===

==== include words ====
more
some
words

==== customer name ====
akbar
amar
anthony
ram
sham

==== cities ====
delhi
mumbai
pune

=== prefix ===
a
an
the


Read more here: https://stackoverflow.com/questions/66345194/sort-words-per-section

Content Attribution

This content was originally published by shantanuo at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: