I have a quick question... I would like to sort the numbers in each line that are within a file, and I want to sort them so that the numbers in each line go from SMALLEST to HIGHEST. For example, my file looks like this:
I don't know how efficient this is, but it might work well enough if your files are small:
awk '
{
split( $0, a, " " );
asort( a );
for( i = 1; i <= length( a ); i++ )
printf( "%d ", a );
printf( "\n" );
}
' input-file >output-file
There used to be a bug in asort , so go with caution. Also, asort is a gnu extension (I believe) so it might not be available. You could write a small sort function in the awk programme; again I don't know how efficient that is. I use a small bubble sort function, to avoid asort, but only in conjunction with small tasks because of a concern for efficiency.
EDIT: I ran a quick test to sort 25 values per line, over 100,000 lines. It took 10.6s on my not so speedy laptop.