如何按特定列对格式进行排序?

时间:2016-12-17 13:38:35

标签: regex linux bash sorting

我有这样的格式:

user: "some_text"

我需要按user按字母顺序对文件进行排序。问题是用户重复时我需要保持"some_text"的位置。 例如:

Jack: "Daniel has an apple"
Daniel: "No"
Daniel: "Jack is a morun"
Daniel: "Alfa and beta"
John: "Blah blah blah"

我试过sort -t':' -k1,1我得到了这个:

Daniel: "Alfa and beta"
Daniel: "Jack is a morun"
Daniel: "No"
Jack: "Daniel has an apple"
John: "Blah blah blah"

我需要:

Daniel: "No"
Daniel: "Jack is a morun"
Daniel: "Alfa and beta"
Jack: "Daniel has an apple"
John: "Blah blah blah"

1 个答案:

答案 0 :(得分:2)

看看GNU sort的选项:

  

import import scala.concurrent.duration.DurationLong import scala.concurrent.{Await, Future} ... ... val setup = db.run(queries).foreach(_ => println("Done, schema created!)) Await.result(setup, 5L.seconds) :通过禁用最后比较来稳定排序

-s

输出:

Daniel: "No"
Daniel: "Jack is a morun"
Daniel: "Alfa and beta"
Jack: "Daniel has an apple"
John: "Blah blah blah"