在Linux中稳定排序 [英] stable sort in linux
本文介绍了在Linux中稳定排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个文件
ksh$ cat test
b d
b c
a b
a a
我想在第一个字段上排序,但我想进行稳定排序,即第二个字段的顺序应保持不变.我希望输出为:
I want to sort on first field but I want stable sort i.e. order of 2nd field should remain the same. I want output as:
a b
a a
b d
b c
如果我尝试:
ksh$sort -k1 -s test
我知道
a a
a b
b c
b d
请帮助
谢谢
推荐答案
您忘记了约束关键字段.默认情况下,它一直使用到行尾.
You forgot to constrain the key fields. By default it uses until the end of the line.
sort -k1,1 -s t.txt
这篇关于在Linux中稳定排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文