http://www.perlmonks.org?node_id=863816


in reply to Count similar characters in a row

Try this,

perl -wle 'while(<>) { $count++ if "rrr" eq join "",(split)[1 .. 3] }; print $count' my_column_file.txt 3

Replies are listed 'Best First'.
Re^2: Count similar characters in a row
by jwkrahn (Abbot) on Oct 06, 2010 at 16:00 UTC
    perl -lane '$count++ if "rrr" eq join "",@F[1 .. 3] }{ print $count' m +y_column_file.txt