Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Counting lines by content

by broquaint (Abbot)
on Oct 09, 2002 at 11:19 UTC ( [id://203888]=note: print w/replies, xml ) Need Help??


in reply to Counting lines by content

You could handle this with a simple two-liner
perl -F: -e 'END { print "$_ $c{$_}\n" for keys %c }' \ -ane '$c{$F[1]}++'
See perlrun for more info on perl's command-line options.
HTH

_________
broquaint

Replies are listed 'Best First'.
Re: Re: Counting lines by content
by willa (Acolyte) on Oct 09, 2002 at 11:35 UTC
    Thanks - I also need to make sure there are no duplicates in the third field. I assume this is easy too...
      This will count the second field ignoring duplicates
      perl -F: -e 'END { print "$_ $c{$_}\n" for keys %c }' \ -ane '$c{$F[1]}++ unless $d{"@F[1,2]"}++'
      I assume this is what you meant no duplicates in the third field.
      HTH

      _________
      broquaint

        Thanks! Works a treat!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://203888]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (7)
As of 2024-04-23 16:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found