Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8112101
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T02:21:46+00:00 2026-06-06T02:21:46+00:00

I have a file that has the following format: 12345 TAB_HERE Name : The

  • 0

I have a file that has the following format:
12345 TAB_HERE Name : The Actual Name TAB_HERE 6785

eg.


1001020 Name : SMITH S ANNALOLA     14570
5701061 Name : MATTHEW SANDY HILL   6440
7001083 Name : TANYA MORRISON MILLER    14406

I want to sort by the last field of numbers.

I’d prefer a simple one line python solution or a linux tool based solution.

I tried using sort -k 3,3n but it did not work.
And I can’t seem to write a single line python code that I can run as python -c “code here”

I looked at the following but to no avail:

http://www.unix.com/unix-dummies-questions-answers/18359-how-do-i-specify-tab-field-separator-sort.html

http://www.unix.com/unix-dummies-questions-answers/30450-sort-third-column-n-command.html

http://www.linuxquestions.org/questions/programming-9/unix-sort-on-multiple-fields-598813/

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T02:21:48+00:00Added an answer on June 6, 2026 at 2:21 am

    Quick solution:

    import sys
    print "".join(sorted(sys.stdin.readlines(), key=lambda x:int(x.split()[-1])))
    

    This solution has some disadvantages. For example, it will not work if you have lines without number at the last field, or if you want sort the data not by the last field but by everything else. In this case you must use regular expressions (re module) and descrive the field that you want to use for sorting in the key function.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a .txt file that has the following details: ID^NAME^DESCRIPTION^IMAGES 123^test^Some text goes
I have a filename that has the following format: timestamp-username-1 This file is constantly
I currently have a text file that has the following: 1 Commercial & Enterprise
I am trying to read an ini file that has the following format: SETTING=VALUE
I have a file which has data in the following format A B -----
I have a file of 12Mb approximately that has the following typology [[1,-154],[2,-100],[3,-28],[4,-66],[5,-222],[6,-309],[7,-196],[8,-50],[9,-53],[10,-209],[11,-355],[12,-350],[13,-269],[14,-264],[15,-392],[16,-513],[17,-515],[18,-434],[19,-418],[20,-505],[21,-592],[22,-559],[23,-422],[24,-384],[25,-539],[26,-716],[27,-713],[28,-593],[29,-534],[30,-647],[31,-813],[32,-857],[33,-711],[34,-582],[35,-594],[36,-700],[37,-721],[38,-600],[39,-487],[40,-490],[41,-589],[42,-630],[43,-502],[44,-365],[45,-340],[46,-403],[47,-420],[48,-291],[49,-136],[50,-98],[51,-218],[52,-285],[53,-198],[54,-52],[55,-58],[56,-213],[57,-334],[58,-301],[59,-195],[60,-195],[61,-324],[62,-470],[63,-465],[64,-378],[65,-381],[66,-546],[67,-734],[68,-767],[69,-695],[70,-683],[71,-804],[72,-991],[73,-1050],[74,-937],[75,-850],[76,-912],[77,-1041],[78,-1065],[79,-972],[80,-931],[81,-1030],[82,-1186],[83,-1233],[84,-1113],[85,-992],[86,-1051],[87,-1206],[88,-1299],[89,-1218],[90,-1112],[91,-1150],[92,-1287],[93,-1345],[94,-1239],[95,-1140],[96,-1147],[97,-1276],[98,-1363],[99,-1312],[100,-1206],[101,-1184],[102,-1297],[103,-1378],[104,-1297],[105,-1141],[106,-1113],[107,-1219],[108,-1325],[109,-1284],[110,-1147],[111,-1103],[112,-1179],[113,-1300],[114,-1262],[115,-1141], I'd
I have a file which has contents on every line following this format (A,
If i have a CSV file that is in the following format fd!,sdf,dsfds,dsfd fd!,asdf,dsfds,dsfd
I have a test file that has many lines, each line looks something like:
I have an XML file that has a number of nodes, each of which

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.