All the levels should be sorted alphabetically (but must be kept with their parent)
File Example:
first
apple
orange
train
car
kiwi
third
orange
apple
plane
second
lemon
Expected Result:
first
apple
kiwi
orange
car
train
second
lemon
third
apple
plane
orange
The following command has been used but it works only if the file has only two levels into the tree.
sed '/^[^[:blank:]]/h;//!G;s/\(.*\)\n\(.*\)/\2\x02\1/' infile | sort | sed 's/.*\x02//'
How can I do to sort all the levels correctly?
Thanks in advance
{}(code sample) on selected fragmentfirst,second(1st level) values?