Sponsored Content
Full Discussion: finding duplicates with perl
Top Forums Shell Programming and Scripting finding duplicates with perl Post 33979 by criglerj on Tuesday 28th of January 2003 11:50:54 AM
Old 01-28-2003
Okay, if you need the list of @reports in an array for some other reason, the next best thing is a hash just to gather the duplicates. You can destroy the hash later if you need to. Warning: untested code
Code:
%h = ();
foreach $r (@reports) {
    if (!exists($h{$r}))  {
        # First time we've seen this one
        $h{$r} = 0
    } elsif ($h{$r}) {
        # We've seen this one before and reported
        $h{$r}++
    } else {
        # Second time, so report the duplicate
        print DUPS "\n $r";
        $h{$r} = 1
    }
}
%h = ();   # Destroy %h if you're done with it

Now %h contains the number of "extra" of each member of @reports, i.e, one less than the number that's actually there. If you don't need @reports for anything else, you can embed this logic into the loop thats reading your large data file and save some memory.

Another option is to put off the reporting of duplicates, putting that in another loop after the one shown above so you can report the number of times a report is found in @reports.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

finding duplicates in columns and removing lines

I am trying to figure out how to scan a file like so: 1 ralphs office","555-555-5555","ralph@mail.com","www.ralph.com 2 margies office","555-555-5555","ralph@mail.com","www.ralph.com 3 kims office","555-555-5555","kims@mail.com","www.ralph.com 4 tims... (17 Replies)
Discussion started by: totus
17 Replies

2. Shell Programming and Scripting

Finding duplicates from positioned substring across lines

I have million's of records each containing exactly 50 characters and have to check the uniqueness of 4 character substring of 50 character (postion known prior) and report if any duplicates are found. Eg. data... AAAA00000000000000XXXX0000 0000000000... upto50 chars... (2 Replies)
Discussion started by: gapprasath
2 Replies

3. Shell Programming and Scripting

Help finding non duplicates

I am currently creating a script to find filenames that are listed once in an input file (find non duplicates). I then want to report those single files in another file. Here is the function that I have so far: function dups_filenames { file2="" file1="" file="" dn="" ch="" pn="" ... (6 Replies)
Discussion started by: chipblah84
6 Replies

4. Shell Programming and Scripting

finding duplicates in csv based on key columns

Hi team, I have 20 columns csv files. i want to find the duplicates in that file based on the column1 column10 column4 column6 coulnn8 coulunm2 . if those columns have same values . then it should be a duplicate record. can one help me on finding the duplicates, Thanks in advance. ... (2 Replies)
Discussion started by: baskivs
2 Replies

5. UNIX for Dummies Questions & Answers

Finding duplicates then copying, almost there, maybe?

Hi everyone. I'm trying to help my wife with a project, she has exported 200 images from many different folders, unfortunately there was a problem with the export and I need to find the master versions so that she doesn't have to go through and select them again. I need to: For each image in... (2 Replies)
Discussion started by: Rhinoskin
2 Replies

6. Shell Programming and Scripting

Perl, sorting and eliminating duplicates

Hi guys! I'm trying to eliminate some duplicates from a file but I'm like this :wall: !!! My file looks like this: ID_1 0.02 ID_2 2.4e-2 ID_2 4.3.e-9 ID_3 0.003 ID_4 0.2 ID_4 0.05 ID_5 1.2e-3 What I need is to eliminate all the duplicates considering the first column (in this... (6 Replies)
Discussion started by: gabrysfe
6 Replies

7. Shell Programming and Scripting

Finding duplicates in a file excluding specific pattern

I have unix file like below >newuser newuser <hello hello newone I want to find the unique values in the file(excluding <,>),so that the out put should be >newuser <hello newone can any body tell me what is command to get this new file. (7 Replies)
Discussion started by: shiva2985
7 Replies

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

9. Shell Programming and Scripting

UNIX scripting for finding duplicates and null records in pk columns

Hi, I have a requirement.for eg: i have a text file with pipe symbol as delimiter(|) with 4 columns a,b,c,d. Here a and b are primary key columns.. i want to process that file to find the duplicates and null values are in primary key columns(a,b) . I want to write the unique records in which... (5 Replies)
Discussion started by: praveenraj.1991
5 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
Benchmark::Timer(3pm)					User Contributed Perl Documentation				     Benchmark::Timer(3pm)

NAME
Benchmark::Timer - Benchmarking with statistical confidence SYNOPSIS
# Non-statistical usage use Benchmark::Timer; $t = Benchmark::Timer->new(skip => 1); for(1 .. 1000) { $t->start('tag'); &long_running_operation(); $t->stop('tag'); } print $t->report; # -------------------------------------------------------------------- # Statistical usage use Benchmark::Timer; $t = Benchmark::Timer->new(skip => 1, confidence => 97.5, error => 2); while($t->need_more_samples('tag')) { $t->start('tag'); &long_running_operation(); $t->stop('tag'); } print $t->report; DESCRIPTION
The Benchmark::Timer class allows you to time portions of code conveniently, as well as benchmark code by allowing timings of repeated trials. It is perfect for when you need more precise information about the running time of portions of your code than the Benchmark module will give you, but don't want to go all out and profile your code. The methodology is simple; create a Benchmark::Timer object, and wrap portions of code that you want to benchmark with "start()" and "stop()" method calls. You can supply a tag to those methods if you plan to time multiple portions of code. If you provide error and confidence values, you can also use "need_more_samples()" to determine, statistically, whether you need to collect more data. After you have run your code, you can obtain information about the running time by calling the "results()" method, or get a descriptive benchmark report by calling "report()". If you run your code over multiple trials, the average time is reported. This is wonderful for benchmarking time-critical portions of code in a rigorous way. You can also optionally choose to skip any number of initial trials to cut down on initial case irregularities. METHODS
In all of the following methods, $tag refers to the user-supplied name of the code being timed. Unless otherwise specified, $tag defaults to the tag of the last call to "start()", or "_default" if "start()" was not previously called with a tag. $t = Benchmark::Timer->new( [options] ); Constructor for the Benchmark::Timer object; returns a reference to a timer object. Takes the following named arguments: skip The number of trials (if any) to skip before recording timing information. minimum The minimum number of trials to run. error A percentage between 0 and 100 which indicates how much error you are willing to tolerate in the average time measured by the benchmark. For example, a value of 1 means that you want the reported average time to be within 1% of the real average time. "need_more_samples()" will use this value to determine when it is okay to stop collecting data. If you specify an error you must also specify a confidence. confidence A percentage between 0 and 100 which indicates how confident you want to be in the error measured by the benchmark. For example, a value of 97.5 means that you want to be 97.5% confident that the real average time is within the error margin you have specified. "need_more_samples()" will use this value to compute the estimated error for the collected data, so that it can determine when it is okay to stop. If you specify a confidence you must also specify an error. $t->reset; Reset the timer object to the pristine state it started in. Erase all memory of tags and any previously accumulated timings. Returns a reference to the timer object. It takes the same arguments the constructor takes. $t->start($tag); Record the current time so that when "stop()" is called, we can calculate an elapsed time. $t->stop($tag); Record timing information. If $tag is supplied, it must correspond to one given to a previously called "start()" call. It returns the elapsed time in milliseconds. "stop()" croaks if the timer gets out of sync (e.g. the number of "start()"s does not match the number of "stop()"s.) $t->need_more_samples($tag); Compute the estimated error in the average of the data collected thus far, and return true if that error exceeds the user-specified error. If a $tag is supplied, it must correspond to one given to a previously called "start()" call. This routine assumes that the data are normally distributed. $t->report($tag); Returns a string containing a simple report on the collected timings for $tag. This report contains the number of trials run, the total time taken, and, if more than one trial was run, the average time needed to run one trial and error information. "report()" will complain (via a warning) if a tag is still active. $t->reports; In a scalar context, returns a string containing a simple report on the collected timings for all tags. The report is a concatenation of the individual tag reports, in the original tag order. In an list context, returns a hash keyed by tag and containing reports for each tag. The return value is actually an array, so that the original tag order is preserved if you assign to an array instead of a hash. "reports()" will complain (via a warning) if a tag is still active. $t->result($tag); Return the time it took for $tag to elapse, or the mean time it took for $tag to elapse once, if $tag was used to time code more than once. "result()" will complain (via a warning) if a tag is still active. $t->results; Returns the timing data as a hash keyed on tags where each value is the time it took to run that code, or the average time it took, if that code ran more than once. In scalar context it returns a reference to that hash. The return value is actually an array, so that the original tag order is preserved if you assign to an array instead of a hash. $t->data($tag), $t->data; These methods are useful if you want to recover the full internal timing data to roll your own reports. If called with a $tag, returns the raw timing data for that $tag as an array (or a reference to an array if called in scalar context). This is useful for feeding to something like the Statistics::Descriptive package. If called with no arguments, returns the raw timing data as a hash keyed on tags, where the values of the hash are lists of timings for that code. In scalar context, it returns a reference to that hash. As with "results()", the data is internally represented as an array so you can recover the original tag order by assigning to an array instead of a hash. BUGS
Benchmarking is an inherently futile activity, fraught with uncertainty not dissimilar to that experienced in quantum mechanics. But things are a little better if you apply statistics. LICENSE
This code is distributed under the GNU General Public License (GPL). See the file LICENSE in the distribution, http://www.opensource.org/gpl-license.html, and http://www.opensource.org/. AUTHOR
The original code (written before April 20, 2001) was written by Andrew Ho <andrew@zeuscat.com>, and is copyright (c) 2000-2001 Andrew Ho. Versions up to 0.5 are distributed under the same terms as Perl. Maintenance of this module is now being done by David Coppit <david@coppit.org>. SEE ALSO
Benchmark, Time::HiRes, Time::Stopwatch, Statistics::Descriptive perl v5.10.1 2009-12-03 Benchmark::Timer(3pm)
All times are GMT -4. The time now is 08:27 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy