linux 行长度
I have a text file with many lines of text.
我有一个包含多行文本的文本文件。
In Linux, how to sort the lines by their length?
在Linux中 ,如何按行长排序?
You can make use of awk
together with the sort
program like
您可以将awk
与sort
程序一起使用,例如
awk '{print length(), $0 | "sort -n" }' /path/to/text/file
Here, we use awk
to calculate the text length and sort -n
to sort by the length as numbers.
在这里,我们使用awk
来计算文本长度,并使用sort -n
来对长度进行数字排序。
If you want the original text only, you may use cut
or awk
again to filter away the leading number for the length.
如果只需要原始文本,则可以再次使用cut
或awk
过滤掉长度的前导数字。
Answered by Eric Z Ma.
埃里克·马(Eric Z Ma)回答。
翻译自: https://www.systutorials.com/how-to-sort-lines-by-length-in-linux/
linux 行长度