Answer the question
In order to leave comments, you need to log in
Sorting in a string via sort, how is the delimiter specified?
There is a line:
00000000000000;000022233333;2;NONE;true;100,100,5,1,28;UNKNOWN
You need to sort the numbers 100,100,5,1,28 in descending order.
Answer the question
In order to leave comments, you need to log in
sort does not know how, as far as I remember, it sorts the lines from the very beginning. I recommend considering the option using awk or rearranging the fields (this can be combined).
Just like that:
STRING="000000000000000;0000000000022222233333;2;NONE;true;100,100,5,1,28;UNKNOWN"
echo $STRING
NUMBERS=$(echo $STRING | cut -d';' -f 6)
SORTSTRING=${NUMBERS//,/\\n}
SORTED=$( echo $(echo -e $SORTSTRING | sed 's/,/\n/' | sort -n ) | sed 's/ /,/g')
STRING2=${STRING/$NUMBERS/$SORTED}
echo $STRING2
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question