views:

46

answers:

2

I would like to sort the characters in a string.

e.g.

echo cba | sort-command
abc

Is there a command that will allow me to do this or will I have to write an awk script to iterate over the string and sort it?

Thanks

+2  A: 

This is cheating (because it uses Perl), but works. :-P

echo cba | perl -pe 'chomp; $_ = join "", sort split //'
Chris Jester-Young
or Ruby ;)`echo cba | ruby -e 'puts ARGF.read.split(%r{\s*}).sort.join'`
Mike Nelson
+2  A: 
echo cba | grep -o . | sort |tr -d "\n"
ghostdog74