in reply to Re^3: how to change this code into perl
in thread how to change this code into perl

Hi poj, thank you for the quick response, I tried the script and could not get the duplicate rows, the outcome came up with zero rows. below is the script i tried

open IN,'<','/home/scripts/imageoutcome.txt' or die "Could not open $i +nfile : $!"; my %count = (); my @lines = (); while (<IN>){ push @lines,$_; # print $_; if (/^(\S+)/){ ++$count{$1}; } } close IN; open OUT,'>','/home/scripts/outcome.txt' or die "Could not open $outfi +le : $!"; #print @lines; for (@lines){ if (/^(\S+)/){ print $count{$1}; print OUT $_ if $count{$1} > 0; } } close OUT;

Replies are listed 'Best First'.
Re^5: how to change this code into perl
by poj (Abbot) on Aug 30, 2015 at 19:15 UTC

    Did you try it with the sample you provided ?

    1 twenty 2 thirty 1 forty 1 fifty

    Update : Does your file have spaces at the beginning of the lines ?

    poj

      It seems like some special characters and space, I delete those and its working perfectly now