中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-08-12 10:04
47,811 topics / 349,897 posts / today 0 new / 48,256 members
DOS批处理 & 脚本技术(批处理室) » How to add a line below after searching for a certain field?
Printable Version  1,607 / 4
Floor1 mydosp Posted 2010-12-24 23:15
新手上路 Posts 3 Credits 0
For example:
There is a Txtsetup.sif file that contains two fields: [HiveInfs.Fresh] and [SourceDisksFiles].

I want to add a line of characters "AddReg = settings.inf,update" under [HiveInfs.Fresh].

Under the [SourceDisksFiles] field, add two lines of characters respectively:
settings.inf =1,,,,,,_x,3,,3
settings.reg =100,,,,,,,2,0,0

It should be noted that there are several lines of characters under the [HiveInfs.Fresh] and [SourceDisksFiles] fields themselves.

How to use batch processing to add the characters under these two fields? I am just learning batch processing, please give me some advice.
Floor2 Hanyeguxing Posted 2010-12-25 06:29
银牌会员 Posts 897 Credits 1,039 From 在地狱中仰望天堂
Requirement: This file is in ANSI encoding, and there should be no spaces at the beginning and end. (The processed file will delete blank lines)


[ Last edited by Hanyeguxing on 2010-12-25 at 06:31 ]
Floor3 mydosp Posted 2010-12-25 12:37
新手上路 Posts 3 Credits 0
Hanyeguxing, the batch processing test was successful. But this batch processing removed the spaces at the beginning and end of the text to be added (Txtsetup.sif) as well as the blank lines in the middle of the text, but I want to keep these. How should I do it? Thank you for your help.

Also, I tested the following batch processing, but it's too slow, not as fast as yours, but this one doesn't delete blank lines. Please see:
……………………………………………………………………………………………………
@echo off
for /f "delims=" %%a in (TXTSETUP.SIF) do (
echo/%%a|findstr /xic:"" >nul && (
(echo/%%a
ehco settings.inf=1,,,,,,_x,3,,3
ehco settings.reg=100,,,,,,,2,0,0)>>newfile.txt
)||(echo/%%a>>newfile.txt)
)

copy /y newfile.txt TXTSETUP.SIF >nul && del newfile.txt
………………………………………………………………………………………
Thank you for your advice!

[ Last edited by mydosp on 2010-12-25 at 17:17 ]
Floor4 Hanyeguxing Posted 2010-12-25 19:18
银牌会员 Posts 897 Credits 1,039 From 在地狱中仰望天堂
@echo off&setlocal enableDelayedExpansion
(for /f "tokens=1* delims=:" %%a in ('findstr /n .* "Txtsetup.sif"') do (
echo/%%b
set b=%%b
set b=!b: =!
if "!b!"=="" echo AddReg = settings.inf,update
if "!b!"=="" (
echo settings.inf =1,,,,,,_x,3,,3
echo settings.reg =100,,,,,,,2,0,0
)
))>han.ye
move han.ye Txtsetup.sif

[ Last edited by Hanyeguxing on 2010-12-25 at 19:30 ]
Floor5 mydosp Posted 2010-12-25 19:27
新手上路 Posts 3 Credits 0
Thanks! This batch processing was very successful. I'm researching how to customize the XP installation version, thank you for your help. In the future, I will still need to ask you for advice.
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023