in reply to Re: Read file line by line and check equal lines
in thread Read file line by line and check equal lines

Mcdarren,
I like your 1st version, but it seems to me it'll only work for even nums of duplicates eg if an item occurs 3 (5,7,9...) times, it'll be re-instated/preserved by your script?
Of course, the OP's example file only has duplicates in 2s, but the description doesn't state whether this is always the case.
I agree about using a hash, but I'd keep a count of all lines and test for cnt == 1 after looping through the input

Cheers
Chris

  • Comment on Re^2: Read file line by line and check equal lines

Replies are listed 'Best First'.
Re^3: Read file line by line and check equal lines
by McDarren (Abbot) on Mar 07, 2007 at 07:15 UTC
    Yes, you're absolutely correct - nice catch :)

    Here's an updated one-liner that addresses that problem in the way you suggest:

    perl -ne '$x{$_}++;}{for(sort keys %x){print if $x{$_}==1;}' < input.t +xt

    (I'm not a golfer by any strech of the imagination, so I imagine that could be shortened significantly)

    Cheers,
    Darren :)