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
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
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
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
happy.pl
#!/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);
}
}
$ happy.pl file
johnm100222
maryyy00122
johnmm00003
Replace 3 in above code by the number of invoices you require
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