Visit Our UNIX and Linux User Community


script for remove descending order number


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting script for remove descending order number
# 1  
Old 09-22-2011
script for remove descending order number

hi all
i want to remove some descending order number

example :
Code:
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

Last edited by Scott; 09-22-2011 at 08:01 AM.. Reason: Please use code tags
# 2  
Old 09-22-2011
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?
# 3  
Old 09-22-2011
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 .
# 4  
Old 09-22-2011
Something like this?
Code:
awk '!n{n=$NF}($NF>=n){print;n=$NF}/#/{print;n=0}' file

This User Gave Thanks to Franklin52 For This Post:
# 5  
Old 09-22-2011
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 Smilie
once again thanks Mr .Franklin
# 6  
Old 09-22-2011
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...
Code:
#! /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
#

This User Gave Thanks to Skrynesaver For This Post:
# 7  
Old 09-23-2011
Quote:
Originally Posted by nithyanandan
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 Smilie
once again thanks Mr .Franklin
With the given input file I get the desired output:
Code:
$ 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
#


Previous Thread | Next Thread
Test Your Knowledge in Computers #863
Difficulty: Medium
Vue features a reactivity system that uses jQuery objects and optimized re-rendering.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to sort list of directories in descending order in perl?

Hi, I have a problem . I have few directories like inpTDT_1, inpTDT_2, inpTDT_3 and so on inside HOME directory . In one of my perl script (which is in my HOME), the above directories like inpTDT_1, inpTDT_2, inpTDT_3 are sorting out in an order So I wanted to sort all the inpTDT_1, inpTDT_2,... (1 Reply)
Discussion started by: venkatesh
1 Replies

2. Shell Programming and Scripting

How to remove no max value and order?

How do I remove maxvalue and noorder? I've a list of files with the following similar content Prompt Sequence SEQ_AD_ID; CREATE SEQUENCE SEQ_AD_ID START WITH 1 MAXVALUE 1000000000000 MINVALUE 1 NOCYCLE CACHE 10 NOORDER; to Prompt Sequence SEQ_AD_ID; CREATE... (2 Replies)
Discussion started by: jediwannabe
2 Replies

3. UNIX for Dummies Questions & Answers

Sorting a file in descending order when you have 10e- values

Hi, I am trying to sort the following file in descending order of its fourth column. 2 1 363828 -2.423225e-03 3 1 363828 4.132763e-03 3 2 363828 8.150133e-03 4 1 363828 4.126890e-03 I use sort -k4,4g -r input.txt > output.txt ... (1 Reply)
Discussion started by: evelibertine
1 Replies

4. Shell Programming and Scripting

Help with sort data based on descending order problem

Input file 9.99331e-13 8.98451e-65 9.98418e-34 7.98319e-08 365592 111669 74942.9 0 Desired output 365592 111669 74942.9 7.98319e-08 1.99331e-13 6.98418e-34 (2 Replies)
Discussion started by: perl_beginner
2 Replies

5. UNIX for Dummies Questions & Answers

how to list descending order

Hi, I want to short descending all the files according to their size.Please help me.. (1 Reply)
Discussion started by: jyotidas
1 Replies

6. Shell Programming and Scripting

Regarding about the print line number/order

Hello, I am trying to print line number/order using this command awk '{print $0, FNR}' myfilename 11006 A41 1888 11006 A41 1888 11006 A41 1888 11006 A41 ... (2 Replies)
Discussion started by: davidkhan
2 Replies

7. UNIX for Dummies Questions & Answers

Help - Find command with list of files modified descending Order

Hi, I would like to know the command to get the files order in descending order with "FIND" command. Appreciate your help Thanks (4 Replies)
Discussion started by: TonySolarisAdmi
4 Replies

8. Shell Programming and Scripting

Ascending & Descending order numbers

Dear All, I have below attached file in which i have many nos, i want the last ascending order nos. The brief description is given below. File 315 381 432 315 381 432 315 381 432 315 381 432 315 381 432 (6 Replies)
Discussion started by: pravani1
6 Replies

9. Shell Programming and Scripting

filter and get the latest order number

hello, how can I filter and get the latest order number (last five digits) below: input file: johnmm00001 maryyy00121 johnm100222 johnmm00003 maryyy00122 output file: johnmm00003 maryyy00122 johnm100222 (6 Replies)
Discussion started by: happyv
6 Replies

10. UNIX for Dummies Questions & Answers

how to see disk usage in descending order

What is the command used by sysadmin to see the disk used by the users in descending order of their disk usage? (8 Replies)
Discussion started by: asutoshch
8 Replies

Featured Tech Videos