Tuesday, January 30, 2024

[SOLVED] How to sort characters in a string?

Issue

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?


Solution

echo cba | grep -o . | sort |tr -d "\n"


Answered By - ghostdog74
Answer Checked By - David Goodson (WPSolving Volunteer)