for example if we have in a variable named “var”
a string “2.test 1.test 9.test”
i want it to be
1.test 2.test 9.test
I was trying to apply this command
echo $var | sort -n
but the output isn’t correct because if for example I have
2.text
11.text
it will print
11.text 2.text which is wrong because 11>2
thanks
sortworks on lines, not words.For the example you’ve shown us, you’re sorting a single line of text. For example:
But that’s inconsistent with the output you’ve shown us, so I can’t be sure just what you’re doing, or what you’re trying to do.
Are you looking for something like this?
And do you need to re-assemble the lines into a single line? Piping the output through
fmt -999will do that, but that’s a bit ugly (GNU coreutilsfmtlimits the width to 2500).