标题: [文本处理] [分享]批处理在文本第三行添加指定内容 [打印本页]
作者: Batcher 时间: 2021-11-6 19:39 标题: [分享]批处理在文本第三行添加指定内容
【问题描述】
Settings.ini内容如下:- [/Script/Engine.GameUserSettings]
- bUseDesiredScreenHeight=False
-
- [ScalabilityGroups]
- sg.ResolutionQuality=100.000000
- sg.ViewDistanceQuality=0
- sg.AntiAliasingQuality=0
- sg.ShadowQuality=0
- sg.PostProcessQuality=0
- sg.TextureQuality=0
- sg.EffectsQuality=0
- sg.FoliageQuality=0
复制代码
需要在第二行下面添加一行:
GraphicsAPI=DX11_Enhanced
作者: Batcher 时间: 2021-11-6 19:40
方案1.bat- @echo off
- setlocal enabledelayedexpansion
- cd /d "%~dp0"
- set "FileOld=Settings.ini"
- set "FileNew=Settings_New.ini"
- set "n=0"
- (for /f "delims=" %%i in ('type "%FileOld%"') do (
- echo,%%i
- set /a n+=1
- if !n! equ 2 (
- goto :next
- )
- ))>"%FileNew%"
-
- :next
- >>"%FileNew%" echo GraphicsAPI=DX11_Enhanced
- >>"%FileNew%" more +2 "%FileOld%"
复制代码
作者: Batcher 时间: 2021-11-6 19:43
方案2.bat- @echo off
- setlocal enabledelayedexpansion
- cd /d "%~dp0"
- set "FileOld=Settings.ini"
- set "FileNew=Settings_New.ini"
- set "n=0"
- (for /f "tokens=1* delims=:" %%i in ('type "%FileOld%" ^| findstr /n .*') do (
- echo,%%j
- set /a n+=1
- if !n! equ 2 (
- echo,GraphicsAPI=DX11_Enhanced
- )
- ))>"%FileNew%"
复制代码
作者: Batcher 时间: 2021-11-6 20:20
方案3.bat- @echo off
- cd /d "%~dp0"
- set "FileOld=Settings.ini"
- set "FileNew=Settings_New.ini"
- (for /f "tokens=1* delims=:" %%i in ('type "%FileOld%" ^| findstr /n .*') do (
- echo,%%j
- if %%i equ 2 (
- echo,GraphicsAPI=DX11_Enhanced
- )
- ))>"%FileNew%"
复制代码
作者: Batcher 时间: 2021-11-6 20:24
方案4 使用命令行工具 sed.exe
http://bcn.bathome.net/s/tool/index.html?key=sed- sed "3iGraphicsAPI=DX11_Enhanced" "Settings.ini" > "Settings_New.ini"
复制代码
欢迎光临 批处理之家 (http://www.bathome.net/) |
Powered by Discuz! 7.2 |