sort strings in csh

3.8k views Asked by At
set abc=( x1 y1 x2 y2 x21 y21 x22 y22 )
set new=`echo $abc | sort -kn`
echo $new

The above script gives me the same array.

I expect

x1 x2 x21 x22 y1 y2 y21 y22

Where did I go wrong ?

1

There are 1 answers

1
Keith Thompson On BEST ANSWER

sort sorts by lines, and you're giving it just a single line of input.

This should work:

set abc = ( x1 y1 x2 y2 x21 y21 x22 y22 )
set new = `echo $abc | fmt -1 | sort -n`
echo $new