如何将文件从短到长的线路进行排序? [英] How to sort the lines in a file from shortest to longest?

查看:106
本文介绍了如何将文件从短到长的线路进行排序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

类似排序从最长的线路最短,我有点哪有所有从短到长文件中的行吗?例如。


这是一个长句子。
这不是那么长。
这不长。

这变成了:


这不长。
这不是那么长。
这是一个长句子。


解决方案

这几乎exactely一样你给的链接

 的awk'{打印长度($ 0),$ 0; }'$文件|排序-n |切-d''-f 2-

-r 选项是扭转了排序。

Similar to Sorting lines from longest to shortest, how can I sort all of the lines in a file from shortest to longest? E.g."

This is a long sentence.
This is not so long.
This is not long.

That becomes:

This is not long.
This is not so long.
This is a long sentence.

解决方案

It's almost exactely the same as in the link you gave

awk '{ print length($0) " " $0; }' $file | sort -n | cut -d ' ' -f 2-

the -r option was for reversing the sort.

这篇关于如何将文件从短到长的线路进行排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆