[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: sort

Mr.Sean is correct.

...a litle bit from my side...

[vipin vipin ~]$ grep -v age testsort.txt | awk '{print $2}' | sort -r

On 6/19/06, Miner, Jonathan W (CSC) (US SSA)
<jonathan w miner baesystems com> wrote:

        -----Original Message-----
        From: redhat-list-bounces redhat com on behalf of Aimin Yan
        Sent: Sat 06/17/2006 02:23 PM
        To: redhat-list redhat com
        Subject: sort

        i have a file, I want to sort this file based on the 2nd column, and start
        from 1st row.how can
        I do use sort command to do in redhat linux.
        for example, this is file I want to sort

        name  age  income
        trorry   34    344
        aimin   36    345
        shihe   23    3667



        Lots of possible answers to this, here is one that preserves the header line, and the rest of the file contents:


        (head -1 $f; awk 'BEGIN {getline} {print $0}' $f | sort -k2 -n) > $f.new

        mv $f.new $f

        This depends on having a single title line in the field, a better method, in my opinion, is to use the pound sign (#) to mark comments.  The code then becomes:


        (grep '^#' $f; grep -v '^#' $f | sort -k2 -n) > $f.new

        mv $f.new $f


redhat-list mailing list
unsubscribe mailto:redhat-list-request redhat com?subject=unsubscribe

...i've to look back when i heard a gong! i could only see a huge
cobweb and its shining, just got wonder, what the time it was…5AgAr

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]