Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

228
Views
How to sort data by the numbers in third column?

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
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

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 type

KEYDEF 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.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!