Results 1 to 5 of 5
Thread: Sorting Words in a Line
Enjoy an ad free experience by logging in. Not a member yet? Register.
Sorting Words in a Line
e.g. if I have:
bass dover carp albacore
I want it to come out like so:
albacore bass carp dover
I could come up with a kludge, but it would be nice to know a real way to do it.
- Join Date
- Jun 2006
H for Homework?
Actually no, I am just a novice enthusiast that would like some help...
I suppose you get a lot of questions here from people in school?
Perhaps the reason my post looks like homework are the fish; I actually started with fruits and decided that I like fish better.
I am writing a script that install a lot of packages with apt-get, and my OCD is telling me to sort them by category (already done) and by name within each category. Basically, I am trying to ease the pain of initial installation, and I want to be able to extend this script elegantly as I find more packages I like/need. Thus is the reason I want them in alphabetical order.
Okay, for now I have a hack that works okay...
tr " " "\n" | sort | tr "\n" " "
- Join Date
- Feb 2009
This is very simple to do in C++, and can be run through the terminal. Although, my knowledge in C++ is limited, so the only way I know to do it is an linked list, which might be over you're head if you don't know C++ already.
It might help to know that you can use "<" or ">" with strings. ("bass" < "carp") will return true.