Re: Sort the file

From: Barry Margolin (barmar_at_alum.mit.edu)
Date: 04/29/04


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 ***


Relevant Pages

  • Duplicate Row Removal Solution
    ... original order following your cleanup. ... sort by the column to be testes ... Sub Test() ... >I have an issue where I'm trying to remove duplicate ...
    (microsoft.public.excel.programming)
  • Re: SORTING question
    ... use this column to be able to sort back to the original order. ... I want to sort and resort on certain columns occasionally, ... "key" column (ala Access) in the fifth column to enable a resort to ...
    (microsoft.public.excel.newusers)
  • RE: Sort A to Z
    ... Once you sort the items if you saved the spreadsheet you will not be able to ... "Misho" wrote: ... the return items to their original order before sortting. ... "Eduardo" wrote: ...
    (microsoft.public.excel.misc)
  • Re: Adding a KeyID column for sorting
    ... > *before* the "return to normal" sort. ... >> MAKE SURE when sorting that you select ALL the data before sorting, ... >> worksheet)? ... >>> original order, so I have to be very careful not to mess things up. ...
    (microsoft.public.excel.newusers)
  • Re: Factorial
    ... and the "best case" for Quicksort (although admittedly QS is pretty ... I should mention that my merging sort does not do recursion, ... sort an array of array-index values (an array of "pointers" although in the ... One of the problems of in-place sorts is that the original order is lost. ...
    (microsoft.public.vb.general.discussion)