2016-12-17 4 views
1

ich habe ein Format wie folgt aus:Wie sortiere ich ein Format nach einer bestimmten Spalte?

user: "some_text" 

i Art der Datei durch die user .Das Problem alphabetisch müssen, ist, wenn der Benutzer Duplikate und i die Position des "some_text" beibehalten müssen. ex:

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

habe ich versucht sort -t':' -k1,1 und ich bekomme diese:

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

ich brauche:

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

Antwort

2

Werfen Sie einen Blick auf Art GNU Wahlen:

-s: stabilisieren sor t durch letztinstanzliche Vergleich zu deaktivieren


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

Ausgang:

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