gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:08:49 26 4
gpt4 key购买 nike

我有这样的格式:

user: "some_text"

我需要按用户的字母顺序对文件进行排序。问题是当用户重复时,我需要保持“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"

最佳答案

看看 GNU sort 的选项:

-s: stabilize sort by disabling last-resort comparison


sort -s -t':' -k1,1 file

输出:

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

关于regex - 如何按特定列对格式进行排序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41199165/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com