infile=$1 for i in $(cat $infile) do echo $i | tr "," "\n" | sort -n | tr "\n" "," | sed "s/,$//" echo done

Sorting by rows

Save the script as: sort_file Usage: sort_file < sort_me.csv > out_file.csv This script was originally posted by Admiral Beotch in LinuxQuestions.org on the Linux-Software forum. I modified this script to make it more portable.
Sample Output
Sort values arranged in rows, like:
x3, x5, x1, x4, x7, x2, x6
x11, x13, x14, x8, x10, x12, x9
... ... ... ... ... ... ...
After executing the script, values will be horizontally sorted:
x1, x2, x3, x4, x5, x6, x7
x8, x9, x10, x11, x12, x13, x14
... ... ... ... ... ... ...
where x1, x2, ..., xn are integers
Each row can have n integers and 
x1 < x2 < x3, ..., < x7
x8 < x9 < x10, ..., < x14
..   ..   ..           ..
After executing the script, each row will be sorted in ascending order.

0
By: iframe
2009-07-12 21:23:37

These Might Interest You

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands



Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: