Unix Programming - Re: Sorting and then removing sort-by cols from a fixed-width flat

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > June 2006 > Re: Sorting and then removing sort-by cols from a fixed-width flat





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Re: Sorting and then removing sort-by cols from a fixed-width flat
Logan Shaw

2006-06-30, 1:20 am

aditya.chaudhary@gmail.com wrote:
> I cannot use a delimiter for just 2 new cols. The file is in
> fixed-width format and I have to format such a file. So kindly suggest
> the sort syntax for fixed width.


Now you're just being inflexible! :-)

I'm not saying the final format has to be with a delimiter. I'm
saying that if you wish to pass it to "sort", you have to have a
delimiter. You can change the format afterwards if you wish.

Personally, I would just write a PERL script.

#! /usr/bin/perl

print
sort
{
substr ($a, 0, 15) <=> substr ($b, 0, 15)
or
substr ($a, 15, 5) <=> substr ($b, 15, 5)
} <>;

That sorts on fixed-width fields. It assumes characters
0 through 14 are numbers and likewise with characters 15
through 19. If you want a string comparison instead, you
could replace one or both of the "<=>" with "cmp".

- Logan
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com