Sort Tab Delimited file in UNIX

Posted on 2005-05-10
Last Modified: 2012-06-21
Hello All,

I have 2 tab delimited files one with 16 and second with 5 million records with 40 columns. My requirement is to concatinate both the files resulting 21 million  and sort on the column numbers (5,10 and 1). I was able to use the cat command to concatinate but not able to sort on the specific fileds. I was able to sort the fixed width files but never tried the tab delimited.

Hope I will be helped with some solutions.

Question by:cutie_smily
    LVL 48

    Expert Comment

    sort +4 +9 +1 file1 file2 >sortedfile

    LVL 48

    Accepted Solution


    sort -k5,5 -k10,10 -k1,1  file1 file2 >sortedfile


    Author Comment

    Thanks for the reply it worked perfectly well. I am little curious here how do we sor the files if we have a delimiter like comma.

    LVL 48

    Expert Comment

    This is all in the man page.



    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    I promised to write further about my project, and here I am.  First, I needed to setup the Primary Server.  You can read how in this article: Setup FreeBSD Server with full HDD encryption (…
    About FreeBSD Jails In FreeBSD, jails are a way of doing operating system level virtualization.  The basis of FreeBSD jails is chroot (, which changes the root directory of processes.  As a…
    Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
    This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now