[NTLUG:Discuss] Sort question
Chris Cox
cjcox at acm.org
Thu Apr 5 22:28:24 CDT 2012
On 04/05/2012 07:39 PM, Fred James wrote:
> Chris Cox wrote:
>> first tr should be '[0-9]' get rid of the carat
>>
>>> Chris Cox wrote:
>>>> My soln in bourne shell script:
>>>> #!/bin/sh
>>>> while read line;do
>>>> echo "$line" | tr -cs '[^0-9]' '\012' | sort -n | tr '\012' ' '
>>>> echo ""
>>>> done
>>>>
>>>> To use: sh thescript.sh <thedatafile
>>>>
>>>>
>>> Very nice
>>> Regards
>>> Fred James
> Chris Cox
> I had wondered about the carat ... but it works in either case ... ¿Por qué, me
> pregunto?
A reasonable question... you could tell had forgotten about the -c option to
complement the character set.. maybe that's the "answer" if you will... the
reason why.. maybe carat has no meaning in that case since it's complementing
the whole set? Just a guess. The -s eliminates the extra non numerics (things
in the complemented set) no matter how many there are (reduces them down to 1,
in case anyone wonders). In short, just give me the numbers and the -cs
compresses the rest to make the numbers followed by a newline... this would
allow the input to look like:
"53","17","3","24","9","33"
even.... but the output would just be the numbers sorted with space as the
separator... again, in case you wondered... however, will have some leading
white space.
More information about the Discuss
mailing list