简体   繁体   中英

unix sort descending order

I want to sort a tab limited file in descending order according to the 5th field of the records.

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. You have to specify both n and r at the same level (globally or locally).

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 .

Also, use the -t command line switch to specify the delimiter to tab . Try this:

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

or if the above doesn't work (with the tab ) this:

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

Finally, this SO question Unix Sort with Tab Delimiter might be helpful.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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