Sponsored Content
Top Forums Shell Programming and Scripting Perl, sorting and eliminating duplicates Post 302650871 by Skrynesaver on Monday 4th of June 2012 11:05:04 AM
Old 06-04-2012
Something like the following should work, WARNING not tested code.

Code:
#!/usr/bin/perl

use strict;
use warnings;
my %values;
open (my $file, "<", $ARGV[0]);
while(<file>){
  my ($id,$val)=/(ID_\d+)\s+(.+)$/;
  if (! defined $values{$id}){
    $values{$id}=sprintf ("%.15f\n",$val);
  }
  elsif (sprintf ("%.15f\n",$val) < $values{$id}){
    $values{$id}=sprintf ("%.15f\n",$val);
  }
}
for (sort keys %values){
  print "$_\t$values{$_};
}

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

finding duplicates with perl

I have a huge file (over 30mb) that I am processing through with perl. I am pulling out a list of filenames and placing it in an array called @reports. I am fine up till here. What I then want to do is go through the array and find any duplicates. If there is a duplicate, output it to the screen.... (3 Replies)
Discussion started by: dangral
3 Replies

2. UNIX for Dummies Questions & Answers

How to remove duplicates without sorting

Hello, I can remove duplicate entries in a file by: sort File1 | uniq > File2 but how can I remove duplicates without sorting the file? I tried cat File1 | uniq > File2 but it doesn't work thanks (4 Replies)
Discussion started by: orahi001
4 Replies

3. Shell Programming and Scripting

perl sorting

I have many files that I need to sort each week. I know how to do in Unix, but for this task it appears best to do native inside an existing perl program. So, simplified, I have a file similar to the following: Joe_________12_Main_St__A001________LX Benny_______5_Spring____A002________LX... (5 Replies)
Discussion started by: joeyg
5 Replies

4. Shell Programming and Scripting

Eliminating duplicates from the who command

I am trying to show how many users are logged into one of my systems. Using who -q it gives me a user count, but some users are logged in multiple times. Is there any easy parameter that I can use to ignore/eliminate these duplicates?? Thanks (9 Replies)
Discussion started by: mikejreading
9 Replies

5. Shell Programming and Scripting

Perl sorting

Hi, I have a file in this format: a b c d e a b c d e a b c d e i need perl script to sort 2nd column in alphabatical order The script i use is #!/usr/bin/perl my @words=<>; foreach(sort mysort @words) { print; (4 Replies)
Discussion started by: Learnerabc
4 Replies

6. Shell Programming and Scripting

HELP on Perl array / sorting - trying to convert Korn Shell Script to Perl

Hi all, Not sure if this should be in the programming forum, but I believe it will get more response under the Shell Programming and Scripting FORUM. Am trying to write a customized df script in Perl and need some help with regards to using arrays and file handlers. At the moment am... (3 Replies)
Discussion started by: newbie_01
3 Replies

7. Shell Programming and Scripting

Need help with eliminating newlines with Perl

Good morning, I need some help with getting rid of newlines with the output from a MYSQL query and putting the information into the right format that I need. Here is the script as it is today: #!/usr/bin/perl my $uda = system("/opt/incontrol/mysql/bin/mysql -u root -ppassword... (2 Replies)
Discussion started by: brianjb
2 Replies

8. Shell Programming and Scripting

Perl Sorting Help

Hey guys, I have started to learn perl recently because of a position I took. They want me to master perl and I've been reading books and practicing myself. Basically I,m having my perl script run through a text pad and give the output in a special way e.g input deviceconfig { ... (5 Replies)
Discussion started by: zee3b
5 Replies

9. Shell Programming and Scripting

PERL "filtering the log file removing the duplicates

Hi folks, I have a log file in the below format and trying to get the output of the unique ones based on mnemonic IN PERL. Could any one please let me know with the code and the logic ? Severity Mnemonic Log Message 7 CLI_SCHEDULER Logfile for scheduled CLI... (3 Replies)
Discussion started by: scriptscript
3 Replies

10. Shell Programming and Scripting

Help in modifying a PERL script to sort Singletons and Duplicates

I have a large database which has the following structure a=b where a is one language and b is the other and = is the delimiter Since the data treats of language, homographs occur i.e. the same word on the left hand side can map in two different entries to two different glosses on the right... (3 Replies)
Discussion started by: gimley
3 Replies
vendorlib(3pm)						User Contributed Perl Documentation					    vendorlib(3pm)

NAME
vendorlib - Use Only Core and Vendor Libraries in @INC SYNOPSIS
#!/usr/bin/perl use vendorlib; use strict; use warnings; use SomeModule; # will only search in core and vendor paths ... DESCRIPTION
In a system distribution such as Debian, it may be advisable for Perl programs to ignore the user's CPAN-installed modules and only use the distribution-provided modules to avoid possible breakage with newer and unpackaged versions of modules. To that end, this pragma will replace your @INC with only the core and vendor @INC paths, ignoring site_perl and $ENV{PERL5LIB} entirely. It is recommended that you put "use vendorlib;" as the first statement in your program, before even "use strict;" and "use warnings;". BUGS
Please report any bugs or feature requests to "bug-vendorlib at rt.cpan.org", or through the web interface at <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=vendorlib>. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. SUPPORT
You can find documentation for this module with the perldoc command. perldoc vendorlib You can also look for information at: o RT: CPAN's request tracker <http://rt.cpan.org/NoAuth/Bugs.html?Dist=vendorlib> o AnnoCPAN: Annotated CPAN documentation <http://annocpan.org/dist/vendorlib> o CPAN Ratings <http://cpanratings.perl.org/d/vendorlib> o Search CPAN <http://search.cpan.org/dist/vendorlib/> ACKNOWLEDGEMENTS
mxey and jawnsy on oftc #debian-perl helped to hash out the design for this. ribasushi reviewed the initial version and pointed out that @INC order matters. AUTHOR
Rafael Kitover, "<rkitover at cpan.org>" LICENSE AND COPYRIGHT
Copyright 2011 Rafael Kitover. This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License. See http://dev.perl.org/licenses/ for more information. perl v5.10.1 2011-01-17 vendorlib(3pm)
All times are GMT -4. The time now is 11:43 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy