sort

Shankar Jha shankar.jha at gmail.com
Wed Jun 28 18:58:56 UTC 2006


Hi,

cat filename; echo -e \n Sorted:- "; cat filename | tail +2 | sort -k2
Shankar RHCE


On 6/20/06, vipin sagar <sagar.vipin at gmail.com> wrote:
>
> Mr.Sean is correct.
>
> ...a litle bit from my side...
>
> [vipin at vipin ~]$ grep -v age testsort.txt | awk '{print $2}' | sort -r
>
>
> On 6/19/06, Miner, Jonathan W (CSC) (US SSA)
> <jonathan.w.miner at baesystems.com> wrote:
> >
> >
> >         -----Original Message-----
> >         From: redhat-list-bounces at redhat.com on behalf of Aimin Yan
> >         Sent: Sat 06/17/2006 02:23 PM
> >         To: redhat-list at redhat.com
> >         Cc:
> >         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
> >
> >         Aimin
> >
> >         -----------------------------
> >
> >         Lots of possible answers to this, here is one that preserves the
> header line, and the rest of the file contents:
> >
> >         f={filename}
> >
> >         (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:
> >
> >         f={filename}
> >
> >         (grep '^#' $f; grep -v '^#' $f | sort -k2 -n) > $f.new
> >
> >         mv $f.new $f
> >
> >
> >
> >         Enjoy
> >
> >
> > --
> > redhat-list mailing list
> > unsubscribe mailto:redhat-list-request at redhat.com?subject=unsubscribe
> > https://www.redhat.com/mailman/listinfo/redhat-list
> >
> >
>
>
> --
> ~O_0~
> ~sagar
> http://vipinsagar.be
> ...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
>
> --
> redhat-list mailing list
> unsubscribe mailto:redhat-list-request at redhat.com?subject=unsubscribe
> https://www.redhat.com/mailman/listinfo/redhat-list
>



More information about the redhat-list mailing list