filter and get the latest order number


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting filter and get the latest order number
# 1  
Old 03-13-2007
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
# 2  
Old 03-13-2007
Whats the criteria to get the latest order number ?
# 3  
Old 03-13-2007
Quote:
Originally Posted by anbu23
Whats the criteria to get the latest order number ?
the bigger number of last 5 digits (which is the invoice number for customer)..and I just need to get latest one...for a month
# 4  
Old 03-13-2007
Sorting

Input File :
cat /tmp/s
johnmm00001
maryyy00121
johnm100222
johnmm00003
maryyy00122

sort -k1.7n,12n /tmp/s
Output :
johnmm00001
johnmm00003
maryyy00121
maryyy00122
johnm100222

Assumptions :There are only 6 alphabets before the numeric digits.

Please let me know if this works. Experts comment on this
# 5  
Old 03-13-2007
Quote:
Originally Posted by ennstate
Input File :
cat /tmp/s
johnmm00001
maryyy00121
johnm100222
johnmm00003
maryyy00122

sort -k1.7n,12n /tmp/s
Output :
johnmm00001
johnmm00003
maryyy00121
maryyy00122
johnm100222

Assumptions :There are only 6 alphabets before the numeric digits.

Please let me know if this works. Experts comment on this
yes...but I need to delete all old invoice number from the same customer:

expect output:
johnmm00003
maryyy00122
johnm100222
# 6  
Old 03-13-2007
Quote:
Originally Posted by happyv
yes...but I need to delete all old invoice number from the same customer:

expect output:
johnmm00003
maryyy00122
johnm100222
happy.pl
Code:
#!/usr/bin/perl
my $no=1;
my $str;
while( <> )
{
        chomp;
        if(/([0-9]{5})$/)
        {
                $hsh{ $_ }=$& ;
        }
}
foreach $char(sort { $hsh{$b} <=> $hsh{$a} } keys %hsh )
{
      $char =~ /([0-9]{5})$/ ;
      if( $str ne "$`" ) {
      $str=$`;
      print "$char\n" if( $no++ <= 3);
      }
}

Code:
$ happy.pl file
johnm100222
maryyy00122
johnmm00003

Replace 3 in above code by the number of invoices you require
# 7  
Old 03-13-2007
Quote:
Originally Posted by happyv
yes...but I need to delete all old invoice number from the same customer:

expect output:
johnmm00003
maryyy00122
johnm100222
Code:
awk '{name = value = $0
      gsub(/[0-9]/,"",name)
      gsub(/[a-zA-Z]/,"",value)
      if ( value > xv[name] ) x[name] = $0; xv[name]=value }
     END { for ( name in x ) print x[name] }' ~/txt

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Filter records in a huge text file from a filter text file

Hi Folks, I have a text file with lots of rows with duplicates in the first column, i want to filter out records based on filter columns in a different filter text file. bash scripting is what i need. Data.txt Name OrderID Quantity Sam 123 300 Jay 342 498 Kev 78 2500 Sam 420 50 Vic 10... (3 Replies)
Discussion started by: tech_frk
3 Replies

2. Shell Programming and Scripting

Parsing log file and print latest number in loop

Hello All, I have an awk script which parses my log file and prints number grepping from a specific line/pattern, now i have to come with a shell script to continue reading the log untill the job is completed, which i would know while reading session log untill process encounters a final... (1 Reply)
Discussion started by: Ariean
1 Replies

3. Shell Programming and Scripting

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... (6 Replies)
Discussion started by: nithyanandan
6 Replies

4. Shell Programming and Scripting

[ask]filter with line number in file

dear all about my last question in fileA.txt (all list line i want to find in fileB.txt) is content of line number fileA.txt 23 34 35 55 59 and fileB.txt is content like 24:asd|ekkk|001|001 123:bca|egsd|210|002 1231:cas|egds|322|231 ... in fileB.txt they have line number like... (5 Replies)
Discussion started by: zvtral
5 Replies

5. Shell Programming and Scripting

Filter certain number of alphabets

filter the ones (ex:>1279_17_27_F3) that have 50letters (ABABABACACACACACAADADADADABABABABAACACACACACACAACAC) in input. And others that are less than 50 have to be ignore and the ones with more than 50 have to trimmed to first 50 letters. Thanx >1279_16_1960_F3 A >1279_16_2010_F3 BCCC... (2 Replies)
Discussion started by: ruby_sgp
2 Replies

6. Shell Programming and Scripting

Help in writing a KSH script to filter the latest record?

Hi All, I have a text file with the folowing content. BANGALORE|1417|2010-02-04 08:41:04.174|dob|xxx BANGALORE|1416|2010-02-04 08:23:19.566|dob|yyy BANGALORE|1415|2010-02-04 08:20:14.497|dob|aaa BANGALORE|1414|2010-02-04 08:19:40.065|dob|vvv BANGALORE|1413|2010-02-04... (4 Replies)
Discussion started by: Karpak
4 Replies

7. Shell Programming and Scripting

Counts a number of unique word contained in the file and print them in alphabetical order

What should be the Shell script that counts a number of unique word contained in a file and print them in alphabetical order line by line? (7 Replies)
Discussion started by: proactiveaditya
7 Replies

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

9. Shell Programming and Scripting

List number in decending order using AWK

Hi All, Can anyone show me how to list the below numbers in decending order? I have a code to find out whats the largest number though but can it be modified to in-corporate in function ? Thanks in advance Input: 20 30 10 40 50 Output: 50 40 30 20 (2 Replies)
Discussion started by: Raynon
2 Replies

10. Shell Programming and Scripting

adding order number in the output file

Hello, I have a list of all order number like below: maryu01001 johnm00003 peter02234 catmy66751 For the above, all number must in 5 digits and I need to add one into the number and output a new list like below: maryu01002 johnm00004 peter02235 catmy66752 How can write a... (20 Replies)
Discussion started by: happyv
20 Replies
Login or Register to Ask a Question