简体   繁体   English

unix排序降序

[英]unix sort descending order

I want to sort a tab limited file in descending order according to the 5th field of the records. 我想根据记录的第5个字段按降序对选项卡限制文件进行排序。

I tried 我试过了

sort -r -k5n filename

But it didn't work. 但它没有用。

The presence of the n option attached to the -k5 causes the global -r option to be ignored for that field. 附加到-k5n选项的存在会导致该字段忽略global -r选项。 You have to specify both n and r at the same level (globally or locally). 您必须在同一级别(全局或本地)指定nr

sort -t $'\t' -k5,5rn

or 要么

sort -rn -t $'\t' -k5,5

If you only want to sort only on the 5th field then use -k5,5 . 如果你只是要排序在第5场,然后使用-k5,5

Also, use the -t command line switch to specify the delimiter to tab . 另外,使用-t命令行开关指定分隔符到tab Try this: 试试这个:

sort  -k5,5 -r -n -t \t filename

or if the above doesn't work (with the tab ) this: 或者如果以上不起作用(使用tab ):

sort  -k5,5 -r -n -t $'\t' filename

The man page for sort states: 排序状态的手册页

-t, --field-separator=SEP use SEP instead of non-blank to blank transition -t, - field-separator = SEP使用SEP而不是非空白到空白转换

Finally, this SO question Unix Sort with Tab Delimiter might be helpful. 最后,这个问题Unix排序标签分隔符可能会有所帮助。

按照大小按顺序列出文件。

find ./ -size +1000M -exec ls -tlrh {} \; |awk -F" " '{print $5,$9}'  | sort -n\

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM