本帖最后由 77七 于 2024-5-12 18:54 编辑
- @echo off
- rem 批处理和文本全部保存为ansi编码格式
-
- set "file=d:\1.txt"
-
- set /p keyword=your_keyword:
- set /a before=4,after=1,all=before+after
- for /l %%l in (1,1,%all%) do (
- call set "w=%%w%% "
- )
- for /f "delims=" %%a in ('find "%keyword%" ^<"%file%"') do (
- set str=%%a
- setlocal enabledelayedexpansion
- for /f "tokens=1-2 delims=骉" %%x in ("!w!!str:%keyword%=骉!!w!") do (
- endlocal
- set str1=%%x
- set str2=%%y
- setlocal enabledelayedexpansion
- echo [!str1:~-%before%!!keyword!!str2:~0,%after%!]
- endlocal
- )
- )
- pause
复制代码
|