Re: Sort the file
From: Barry Margolin (barmar_at_alum.mit.edu)
Date: 04/29/04
- Next message: Charles Demas: "Re: Sort the file"
- Previous message: Piyush Bichhoriya: "Sort the file"
- In reply to: Piyush Bichhoriya: "Sort the file"
- Next in thread: Charles Demas: "Re: Sort the file"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 28 Apr 2004 21:49:51 -0400
In article <a3f3b305.0404281715.69c740c4@posting.google.com>,
bichhoriya@yahoo.com (Piyush Bichhoriya) wrote:
> Hi there
> I'am new here and could use some help
> I have one file
>
> L310
> L400
> L311
> L401
> H4
>
> and i want to sort on first character only to
>
> H4
> L310
> L400
> L311
> L401
>
> I tried many options in sort but nothing is working.
> What i need actually to move last line to top without changing the
> order of other lines.
sort -s -k 1.1,1.2
The -s option makes the sort "stable", meaning that lines that have the
same key retain their original order. This is available in GNU sort,
but I'm not sure how portable it is. If your sort doesn't have this
option, use:
cat -n file | sort -k 2.1,2.2 -k 1n | sed 's/^ *[0-9]* //'
-- Barry Margolin, barmar@alum.mit.edu Arlington, MA *** PLEASE post questions in newsgroups, not directly to me ***
- Next message: Charles Demas: "Re: Sort the file"
- Previous message: Piyush Bichhoriya: "Sort the file"
- In reply to: Piyush Bichhoriya: "Sort the file"
- Next in thread: Charles Demas: "Re: Sort the file"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|