script for remove descending order number

hi all
i want to remove some descending order number

example :

1        100  200 135.00   Gk_wirs   1
               1        100 200  136.00   Gk_wirs   50
               1        110 210  138.00   Gk_wirs   60 
               1        100 200  136.00   Gk_wirs   57  ----> how to remove this line
 #
               2        200  400 135.00   Gk_wirs   1
               2        200  400 135.00   Gk_wirs   45
               2        200  400 135.00   Gk_wirs   651
               2        200  400 135.00   Gk_wirs   120  ----> how to remove this line 
                2        200  400 135.00   Gk_wirs   4550
#

..........................
..........................

up to 200000 set of lines r there

any one help me to remove descending order line using script

Hi nithyanandan,

A couple of things

  1. Your spec is a little bare, I'm not sure I follow the criteria you are using to remove the records indicated, could you outline why the records above should be removed.
  2. Your workings are also a little threadbare, what have you tried and what does it fail to do?

hi Skrynesaver

this records is use for some geographical work!
i have geographical software i have to upload this records in that software , but that software allows only ascending order number . so , in that file some of the place having descending order number . i want to print only ascending order lines.
is there any solution to fix this .

Something like this?

awk '!n{n=$NF}($NF>=n){print;n=$NF}/#/{print;n=0}' file
1 Like

hi Mr.Franklin

        But this above script is printing as it is not removing that  descending order line , is there any other command to solve this  problem this values r creating velocity so it shouldn't decrease value  so i want to remove that line . i can remove manually but near 2000000  lines & more than thousand files r there :\(

once again thanks Mr .Franklin

the following works for me, though you may have to modify it to your specific needs (open the file directly, allow for spaces at the start of the record and other sanity checks etc...

#! /usr/bin/perl -w

use strict;

my $last=0; #assumes positive values only
while(<DATA>){
        chomp (my @record=split(/\s+/,$_));
        #print join(',',@record),"\n";
        if ($record[5] && ($record[5] > $last)){
                print $_;
                $last=$record[5];
        }
        $last=0 if /^#$/;
}

__DATA__
1        100  200 135.00   Gk_wirs   1
1        100 200  136.00   Gk_wirs   50
1        110 210  138.00   Gk_wirs   60
1        100 200  136.00   Gk_wirs   57
#
2        200  400 135.00   Gk_wirs   1
2        200  400 135.00   Gk_wirs   45
2        200  400 135.00   Gk_wirs   651
2        200  400 135.00   Gk_wirs   120
2        200  400 135.00   Gk_wirs   4550
#
1 Like

With the given input file I get the desired output:

$ cat file
1        100  200 135.00   Gk_wirs   1
               1        100 200  136.00   Gk_wirs   50
               1        110 210  138.00   Gk_wirs   60
               1        100 200  136.00   Gk_wirs   57
 #
               2        200  400 135.00   Gk_wirs   1
               2        200  400 135.00   Gk_wirs   45
               2        200  400 135.00   Gk_wirs   651
               2        200  400 135.00   Gk_wirs   120
                2        200  400 135.00   Gk_wirs   4550
#
$
$ awk '!n{n=$NF}($NF>=n){print;n=$NF}/#/{print;n=0}' file
1        100  200 135.00   Gk_wirs   1
               1        100 200  136.00   Gk_wirs   50
               1        110 210  138.00   Gk_wirs   60
 #
               2        200  400 135.00   Gk_wirs   1
               2        200  400 135.00   Gk_wirs   45
               2        200  400 135.00   Gk_wirs   651
                2        200  400 135.00   Gk_wirs   4550
#