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