[ale] Text File Sorting

Wandered Inn esoteric at denali.atlnet.com
Tue Nov 24 13:15:28 EST 1998


"Michael H. Warfield" wrote:
> 

As I recall, sort does not care what the white space is, spaces,
multiple spaces, tabs, whatever (except a newline).  Therefore, if you
want to sort a whitespaced delimited line on, say field 5, ending with
field 9, I believe the following would work:

sort +4 -9 filename > sortedfile

Which says start sorting on field 4 and end on field 9.

sort index's the fields starting with 0.


> Bob Kruger enscribed thusly:
> 
> > I have a text file that I would like to sort starting at column X and
> > ending at column Y.  After going through the docs for unix sort, it appears
> > that I must either have the fields clearly defined using some type of
> > delimiter, or start at the beginnning of the line.  The problem is that the
> > file has differing amounts of white space where the line item is described.
> 
> > Is there a way to use sort or some other tool, and specify an absolute
> > start and finish column in the text file?
> 
>         This may seem a little kludgy but wouldn't this work...
> 
>         sort -t '^L' +0.10 -0.20 < file1 > file2
> 
>         Of course, this assumes that there is no instance of a form feed (^L)
> anywhere in your file.
> 
>         This would sort based on the columns from column 11 (character 10 in
> field 0) to column 21 (character 20 in field 0) inclusive.
> 
>         Is this what you are trying to do?
> 
> > Thanks in advance for any assistance.
> 
> > Regards - Bob Kruger
> 
>         Mike
> --
>  Michael H. Warfield    |  (770) 985-6132   |  mhw at WittsEnd.com
>   (The Mad Wizard)      |  (770) 925-8248   |  http://www.wittsend.com/mhw/
>   NIC whois:  MHW9      |  An optimist believes we live in the best of all
>  PGP Key: 0xDF1DD471    |  possible worlds.  A pessimist is sure of it!

--
Until later: Geoffrey		esoteric at denali.atlnet.com

You mean you paid MONEY for Service Pack '98????






More information about the Ale mailing list