Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Perl script to count the number of control-A characters per line in a file

Tags:

perl

I need to count the number of control A characters in each line of a file and I'm completely stumped because I don't know what the regex for a control A character would be.

like image 280
phileas fogg Avatar asked Dec 21 '22 12:12

phileas fogg


1 Answers

counting number occurrences of ^A per line (as a perl one-liner):

perl -ne '{print tr/\cA//, $/}' file

counting total number occurrences of ^A:

perl -ne '{$c += tr/\cA//}END{print $c, $/}' file

(edit: fixed typo)

like image 123
mhyfritz Avatar answered Dec 24 '22 02:12

mhyfritz