d4vis has asked for the wisdom of the Perl Monks concerning the following question:
As you can see, there are 3 formats that I need ordered. Those that are ddd-FMT-FMT need a numerical sort. Those that are BLOGOddd-FMT-FMT need to be sorted seperately, but also numerically. Everything else can be sorted normally, but I'm going to run the output through a 20 year old ATEX system, so I need to retain the -FMT-FMT and BLOGO tags.953-FMT-FMT 954-FMT-FMT BLOGO93-FMT-FMT 955-FMT-FMT BOXSTART2- +FMT-FMT BOXEND2-FMT-FMT 956-FMT-FMT 413-FMT-FMT DATE1-FMT-FMT + 414-FMT-FMT 415-FMT-FMT 416-FMT-FMT BLOGO107-FMT-FMT 417-F +MT-FMT 419-FMT-FMT 418-FMT-FMT BLOGO63-FMT-FMT 393-FMT-FMT +394-FMT-FMT BLOGO75-FMT-FMT 420-FMT-FMT 421-FMT-FMT 395-FMT-F +MT
#!/usr/bin/perl -w open (FH1, "input.txt") || die "Couldn't open input.txt"; $/ = " "; @records = <FH1>; open (FH2, ">>output.txt") || die "Couldn't open output.txt"; foreach my $record (sort {$a cmp $b} @records) { print FH2 "$record\n"; }
~scribe d4vis
#!/usr/bin/fnord
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: sort on numbers embedded in text
by rlk (Pilgrim) on Oct 09, 2000 at 19:24 UTC | |
|
(tye)Re: sort on numbers embedded in text
by tye (Sage) on Oct 09, 2000 at 20:07 UTC | |
by d4vis (Chaplain) on Oct 09, 2000 at 20:47 UTC | |
|
Re: sort on numbers embedded in text
by Shendal (Hermit) on Oct 09, 2000 at 19:21 UTC | |
|
Re: sort on numbers embedded in text
by merlyn (Sage) on Oct 09, 2000 at 19:09 UTC | |
by d4vis (Chaplain) on Oct 09, 2000 at 19:48 UTC |