If I have a file consisting of data that looks as follows, how would I sort the data based on the numbers in the third column?
The spaces between the first two columns are not tab delimited, but some number of spaces. The space between the second and third column varies based on the size of the number.
Also note that there are spaces within some data of the second column (like lp25( plasmid between ( and p) while others do not have any spaces (like chromosome).
HELIX lp25(plasmid 24437 bp RNA linear 29-AUG-2011
HELIX cp9(plasmid 9586 bp DNA helix 29-AUG-2011
HELIX lp28-1(plasmid 25455 bp DNA linear 29-AUG-2011
HELIX chromosome 911724 bp DNA plasmid 29-AUG-2011
Here you go:
sort -n -k 3 test.txt
From man sort:
-n, --numeric-sort compare according to string numerical value -k, --key=KEYDEF sort via a key; KEYDEF gives location and typeKEYDEF is F[.C][OPTS][,F[.C][OPTS]] for start and stop position, where F is a field number and C a character position in the field; both are origin 1, and the stop position defaults to the line's end. If neither -t nor -b is in effect, characters in a field are counted from the beginning of the preceding whitespace. OPTS is one or more single-letter ordering options [bdfgiMhnRrV], which override global ordering options for that key. If no key is given, use the entire line as the key.
and also interesting:
-t, --field-separator=SEP use SEP instead of non-blank to blank transition
which tells us that the F fields are separated by whitespace.