Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

Hi,

need your help how to move the line if 2nd,& 3rd column are duplicate, compare the value on 6th column. if it's lesser than previous line(6th column), move the line into different files

Input
628801844415 510998000000015 19 22 0 NULL 0 628802944409 510998000000109 4 22 0 NULL 0 628802544405 510998000000205 4 22 0 NULL 0 628802544417 510998000000217 19 22 0 213 0 628802644413 510998000000313 19 22 0 123 0 628802644417 510998000000217 19 22 0 345 0
output File 1
628801844415 510998000000015 19 22 0 NULL 0 628802944409 510998000000109 4 22 0 NULL 0 628802544405 510998000000205 4 22 0 NULL 0 628802644413 510998000000313 19 22 0 123 0 628802644417 510998000000217 19 22 0 345 0
output file2
628802544417 510998000000217 19 22 0 213 0
#!/usr/bin/perl use strict; use warnings; my $file = $ARGV[0] or die "Need to get CSV file on the command line\n +"; my $outfile = $ARGV[1] or die "Need to get output file on the command +line\n"; my $sum = 0; open(my $data, '<', $file) or die "Could not open '$file' $!\n"; open (OUTFILE, "> $outfile") || die "ERROR: opening $outfile\n"; open (OUTFILE_1, "> dup_$outfile") || die "ERROR: opening $outfile\n"; while (my $line = <$data>) { chomp $line; my @fields = split "," , $line, -1;; if (!$a{$fields[1],$fields[2]}++) { $line= join( ",", @fields ) . "\n" ; print OUTFILE ("$line"); } else { $line= join( ",", @fields ) . "\n" ; print OUTFILE_1 ("$line"); } } close ($data); close (OUTFILE); close (OUTFILE_1);

In reply to move the line if particular column is duplicate or more than 1 entries by hyans.milis

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others pondering the Monastery: (7)
    As of 2015-07-04 17:26 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









      Results (60 votes), past polls