标题: [文本处理] 批处理for命令delims字符分割问题 [打印本页]
作者: wangchuanxiaolu 时间: 2020-10-20 15:23 标题: 批处理for命令delims字符分割问题
有个脚本处理文本内容,我以]分割,但是文本内容会出现]]的情况,我想保留一个],该怎么修改- @echo off
- chcp 65001 >nul
- setlocal enabledelayedexpansion
-
- set DB_NAME=test_%random%
- for /f "skip=2 delims=] tokens=1*" %%a in ('find "" /v /n dev.py') do (
- set line=%%b
- if "!line!" == "" (
- echo.>>dev.py.bak
- ) else (
- set line=!line:test_db=%DB_NAME%!
- echo !line!>>dev.py.bak
- )
- )
复制代码
作者: qixiaobin0715 时间: 2020-10-20 16:48
本帖最后由 qixiaobin0715 于 2020-10-23 13:32 编辑
刚刚修改- @echo off
- chcp 65001 >nul
- set DB_NAME=test_%random%
- (for /f "skip=2 delims=" %%a in ('findstr /n .* dev.py') do (
- set "var=%%a"
- setlocal enabledelayedexpansion
- set line=!var:*]=!
- if "!line!" == "" (
- echo.
- ) else (
- set line=!line:*:=!
- if "!line!" == "" (
- echo.
- ) else (
- set line=!line:test_db=%DB_NAME%!
- echo !line!
- )
- )
- endlocal
- ))>dev.py.bak
- pause
复制代码
欢迎光临 批处理之家 (http://www.bathome.net/) |
Powered by Discuz! 7.2 |