China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-06-25 05:06
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » How to add a line below after searching for a certain field? View 1,435 Replies 4
Original Poster Posted 2010-12-24 23:15 ·  中国 山东 泰安 宁阳县 联通
新手上路
Credits 0
Posts 3
Joined 2010-12-21 20:47
15-year member
UID 179622
Gender Female
Status Offline
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.
Floor 2 Posted 2010-12-25 06:29 ·  中国 吉林 延边朝鲜族自治州 延吉市 电信
银牌会员
★★★
正在学习中的菜鸟...
Credits 1,039
Posts 897
Joined 2009-03-01 15:34
17-year member
UID 140302
Gender Male
From 在地狱中仰望天堂
Status Offline
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)
@echo off&setlocal enableDelayedExpansion
(for /f "eol=€ delims=" %%a in (Txtsetup.sif) do (
echo %%a
if "%%a"=="" echo AddReg = settings.inf,update
if "%%a"=="" (
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 06:31 ]
Floor 3 Posted 2010-12-25 12:37 ·  中国 山东 泰安 宁阳县 联通
新手上路
Credits 0
Posts 3
Joined 2010-12-21 20:47
15-year member
UID 179622
Gender Female
Status Offline
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 ]
Floor 4 Posted 2010-12-25 19:18 ·  中国 吉林 延边朝鲜族自治州 延吉市 电信
银牌会员
★★★
正在学习中的菜鸟...
Credits 1,039
Posts 897
Joined 2009-03-01 15:34
17-year member
UID 140302
Gender Male
From 在地狱中仰望天堂
Status Offline
@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 ]
Floor 5 Posted 2010-12-25 19:27 ·  中国 山东 泰安 联通
新手上路
Credits 0
Posts 3
Joined 2010-12-21 20:47
15-year member
UID 179622
Gender Female
Status Offline
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.
Forum Jump: