Say I have this list:
sharpest
tool
in
the
shed
im
not
the
How can I order alphabetically by the non-indented lines and preserve groups of lines? The above should become:
im
not
the
sharpest
tool
in
the
shed
Similar questions exist here and here but I can't seem to make them work for my example.
Hopeful ideas so far
grep -n
somehow, as it gives me the line numbers? I was thinking to first get the line numbers, then order. I guess I'd somehow need to calculate a line range before ordering, and then from there fetch the range of lines somehow. Can't even think how to do this however!sed 1,2p
and further examples here.If your dataset contains just one level of information, the fastest way would be to let Excel group rows for you automatically. Here's how: Select any cell in one of the rows you want to group. Go to the Data tab > Outline group, click the arrow under Group, and select Auto Outline.
Group sorting is a facility available on table worksheets that removes repeated values to make reports easier to analyze. Group sorting has the following effects: The group name is displayed only once at the start of a group. Repeated group name values are removed from the worksheet.
If perl
is okay:
$ perl -0777 -ne 'print sort split /\n\K(?=\S)/' ip.txt
im
not
the
sharpest
tool
in
the
shed
-0777
slurp entire file, so solution not suitable if input is too bigsplit /\n\K(?=\S)/
gives array using newline character followed by non-whitespace character as split indicationsort
to sort the arrayIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With