in reply to count the number of occurrences of a pattern in a file
~/sandbox$ perl -pe '$_=()=/XY[0-9]+/g;$_.="\n"' junk.txt 5 5
Note of course that your posted code would fail (single quotes don't interpolate so you are splitting on literal backslashes) and your link is broken. I've attempted to replicate your code's intended behavior (outputting new-line separated counts) rather than your stated goal (total occurrence in file).
|
|---|