If I understand your requirements correctly the following sample should do it for you:
#!/usr/bin/perl
use strict;
use warnings;
my $inData = <<IN;
ID1 ch1 70 mir abc xyz ch2 2050
ID2 ch1 90 mir abc xyz ch2 4000
ID3 ch1 100 mir abc xyz ch2 2045
ID4 ch1 120 mir abc xyz ch2 2025
IN
open my $inFile, '<', \$inData;
my @lines = sort {$a->[1] <=> $b->[1]} map {/(\d+)$/; [$_, $1]} <$inFi
+le>;
pop @lines if $lines[-1][1] - $lines[0][1] >= 500;
print for sort map {$_->[0]} @lines;
Prints:
ID1 ch1 70 mir abc xyz ch2 2050
ID3 ch1 100 mir abc xyz ch2 2045
ID4 ch1 120 mir abc xyz ch2 2025
The trick is to pair the line text with the sort key (done in the map) then subsequently use the key or the original line as required.
True laziness is hard work
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.