Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[Solved]Wortliste nach Wortlänge sortieren?
View unanswered posts
View posts from last 24 hours
View posts from last 7 days

 
Reply to topic    Gentoo Forums Forum Index Deutsches Forum (German)
View previous topic :: View next topic  
Author Message
nillsen
Apprentice
Apprentice


Joined: 13 Mar 2004
Posts: 150
Location: /world/eu/ger/sh/nms/

PostPosted: Tue Jun 14, 2005 11:29 am    Post subject: [Solved]Wortliste nach Wortlänge sortieren? Reply with quote

Hallo Leute,

ich möchte eine plaintext Datei sortieren. In jeder Zeile steht genau ein Wort. Sortiert werden soll nach der länge des Wortes - das kürzeste zuerst, das längste zum Ende. Hat jemand da n Denkansatz für mich? Evtl. was mit sed oder awk??? sort bietet die Option ja nicht :-(
Danke schonmal!


€dit: [Solved] hinzugefügt :)
_________________
Also tragt es in die Welt, haut es mit Edding an die Wände.
so lang die dicke Frau noch singt, ist die Oper nicht zu ende.


Last edited by nillsen on Tue Jun 14, 2005 1:00 pm; edited 1 time in total
Back to top
View user's profile Send private message
Rüpel
Guru
Guru


Joined: 06 Nov 2002
Posts: 316
Location: Berlin/Germany

PostPosted: Tue Jun 14, 2005 12:28 pm    Post subject: Reply with quote

was besseres fällt mir jetzt nicht ein:
Code:
for i in $(cat datei); do echo ${#i} $i; done | sort | cut -d ' ' -f 2


der trick kommt von der bash:
Code:
${#variable}
gibt die länge des inhalts von $variable aus.

siehe zum beispiel: > hier <
_________________
:wq
Back to top
View user's profile Send private message
nillsen
Apprentice
Apprentice


Joined: 13 Mar 2004
Posts: 150
Location: /world/eu/ger/sh/nms/

PostPosted: Tue Jun 14, 2005 12:59 pm    Post subject: Reply with quote

Rüpel wrote:
was besseres fällt mir jetzt nicht ein:


Was bessere brauche ich auch nicht, funktioniert nämlich astrein!

Danke :D
_________________
Also tragt es in die Welt, haut es mit Edding an die Wände.
so lang die dicke Frau noch singt, ist die Oper nicht zu ende.
Back to top
View user's profile Send private message
Rüpel
Guru
Guru


Joined: 06 Nov 2002
Posts: 316
Location: Berlin/Germany

PostPosted: Tue Jun 14, 2005 1:54 pm    Post subject: Reply with quote

:D
_________________
:wq
Back to top
View user's profile Send private message
Earthwings
Bodhisattva
Bodhisattva


Joined: 14 Apr 2003
Posts: 7753
Location: Germany

PostPosted: Tue Jun 14, 2005 2:48 pm    Post subject: Reply with quote

Das funktioniert so nur für kurze Worte. Häng als Parameter für sort noch -n an, damit er numerisch sortiert (anderfalls gilt 12 < 8 etc.)
_________________
KDE
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Deutsches Forum (German) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum