文本操作还是用脚本比较好。一种批处理解决方案:
@echo off
:: 文本文件
set textfile=test.txt
:: 要找的字符
set char=.
:: 一行最长有多长
set /a width=1000
setlocal enabledelayedexpansion
set /a num=0
for /f "delims=" %%i in (%textfile%) do (
set oneline=%%i
for /l %%j in (0,1,%width%) do if "!oneline:~%%j,1!"=="%char%" set /a num+=1
)
echo 文件%textfile%中字符串%string%出现的次数是%num%次。
pause > nul