标题: [其他] bat 如何插入换行符 [打印本页]
作者: chenkuan9yy 时间: 2017-11-20 16:23 标题: bat 如何插入换行符
setlocal enabledelayedexpansion
set file=d:\my.ini
set "file=%file:"=%"
for %%i in ("%file%") do set file=%%~fi
echo.
set replaced=[mysqld]
echo.
set all="[mysqld] lower_case_table_names = 2"
for /f " tokens=1 delims=" %%i in ('type "%file%"') do (
set str=%%i
set "str=!str:%replaced%=%all%!"
REM set str=!str: =^
echo !str!>>"%file%"_tmp.txt
)
my.ini 文件内容是这样的
[mysqld]
lower_case_table_names = 1
我想替换好后变成这样
[mysqld]
lower_case_table_names = 2
但是现在是这样的
[mysqld] lower_case_table_names = 1
请问怎么 替换后能换行
作者: WHY 时间: 2017-11-21 11:23
- @echo off
- setlocal enabledelayedexpansion
- for /f "delims=" %%i in (my.ini) do (
- if "!s!" == "[mysqld]" (
- set "s1=%%i"
- if /i "!s1:~0,22!" == "lower_case_table_names" (
- echo;lower_case_table_names = 2
- )
- ) else (echo;%%i)
- set "s=%%i"
- )
- pause
复制代码
作者: 老刘1号 时间: 2017-11-21 22:10
本帖最后由 老刘1号 于 2017-11-21 22:14 编辑
需要管理员权限- Call :EditIni "%~dp0my.ini" mysqld "lower_case_table_names=,lower_case_table_names = 2"
- GOTO :Eof
- :EditIni
- @Echo off
- Pushd %Tmp%
- (For %%a in (
- "[Version]"
- "Signature=$Chicago$"
- "[DefaultInstall]"
- "UpdateInis=2333"
- "[2333]"
- ) Do Echo %%~a)>.\inftmp.Inf
- Echo "%~1","%~2",%~3 >>.\inftmp.Inf
- RUNDLL32 SETUPAPI.DLL,InstallHinfSection ^
- DefaultInstall 128 .\inftmp.INF
- Popd
复制代码
来自:INF文件在批处理中的应用
欢迎光临 批处理之家 (http://bbs.bathome.net/) |
Powered by Discuz! 7.2 |