[NTLUG:Discuss] Sort question
Chris Cox
cjcox at acm.org
Thu Apr 5 15:59:42 CDT 2012
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
> I have a long table with 6 columns of numbers. I want each row of 6
> numbers to
>
> be arranged in ascending order and separated by some delimiter such as
> comma or space, like this:
>
> 53 17 3 24 9 33
>
> 16 8 42 29 1 20
> <etc>
>
> would become
>
> 3 9 17 24 33 53
> 1 8 16 20 29 42
> <etc>
>
> My code was getting really stupid but that was maybe because it was
> really late. Actually, I don't know how to do this. I tried openoffice
> calc
> at first but it scrambled the table. I put the data into a text file but
> none
> of the single digit numbers have a leading zero so none of my feeble
>
> attempts at scripting worked very well.
>
> I might mention that I also have the table in csv format instead of space
> separated, if that might help.
>
>
> Any suggestions?
>
> Thanks,
> Fred
>
>
> _______________________________________________
> http://www.ntlug.org/mailman/listinfo/discuss
>
More information about the Discuss
mailing list