#!/usr/bin/env perl # # count - count identical lines in file # # $Id$ use warnings; use strict; use Getopt::Std; my %opt; getopts( 'hs', \%opt ); &help if $opt{h}; sub help { print STDERR <) { if ( $_ eq $prevl ) { ++$count; } else { print "$count $prevl" if $count; $prevl = $_; $count = 1; } } print "$count $prevl" if $count; } else { my @lines; my %count; while (<>) { if ( !$count{$_}++ ) { # this is the first time we encounter this line push( @lines, $_ ); } } foreach my $l (@lines) { print "$count{$l} $l"; } }