Request a perl one-liner to count matched patterns in a file

Request a perl to count matched patterns in a file. Is one-liner possible? The environment is ms windows. For example,
in test.txt,

aa bb 12 32 24 bc d1 ff f0 cc
24 bc d1 99 0f cd ab db ea 12
12 23 34 45 54 55 21 78 34 89
cd ae de ef ca cb da 24 bc d1
cd 24 bc d1 24 bc d1 ca cb da
.....

Want to count how many pattern "24 bc d1" in this file. Not need to consider the overlapped case such as the line 12 12 12 12 if the matched pattern is "12 12 12".
jl66Asked:
Who is Participating?
 
ozoConnect With a Mentor Commented:
perl -ne "BEGIN{$/='24 bc d1'}$c=chomp;END{print $.-!$c}" test.txt
0
 
farzanjConnect With a Mentor Commented:
Something like

my $pattern = '24 bc d1';
$/ = undef;
my $text = <>;
my (@words) = $text =~ /$pattern/g;
print @words . "\n";
0
 
jl66Author Commented:
Thanks a lot for the solution.
0
All Courses

From novice to tech pro — start learning today.