如果perl没问题的话:
$ perl -0777 -ne 'print sort split /\n\K(?=\S)/' ip.txt
im
not
the
sharpest
tool
in
the
shed
Run Code Online (Sandbox Code Playgroud)
-0777slurp 整个文件,因此如果输入太大,解决方案不适合split /\n\K(?=\S)/使用换行符和后跟非空白字符作为分割指示给出数组sort对数组进行排序