|
mydosp
新手上路

积分 0
发帖 3
注册 2010-12-21
状态 离线
|
『楼 主』:
如何搜索某个字段后在下面添加行?
使用 LLM 解释/回答一下
例如:
有个Txtsetup.sif文件,其中含有 [HiveInfs.Fresh]和 [SourceDisksFiles]两个字段。
我想在 [HiveInfs.Fresh]下面添加:
AddReg = settings.inf,update一行字符,
在 [SourceDisksFiles]字段下面分别添加两行字符:
settings.inf =1,,,,,,_x,3,,3
settings.reg =100,,,,,,,2,0,0
需要注意的是[HiveInfs.Fresh]和[SourceDisksFiles]字段本身下面还有几行字符。
请问如何用批处理实现这两个字段下面字符的添加?本人才学批处理,请赐教。
For example:
There is a Txtsetup.sif file that contains two fields: and .
I want to add a line of characters "AddReg = settings.inf,update" under .
Under the 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 and 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.
|
|
2010-12-24 23:15 |
|
|
Hanyeguxing
银牌会员
     正在学习中的菜鸟...
积分 1039
发帖 897
注册 2009-3-1 来自 在地狱中仰望天堂
状态 离线
|
『第 2 楼』:
使用 LLM 解释/回答一下
要求:此文件ANSI编码,最前、最后不能有空格等(被处理后的文件将删除空行)
@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 ]
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 ]
|

批处理之家 http://bbs.bathome.net/forum-5-1.html |
|
2010-12-25 06:29 |
|
|
mydosp
新手上路

积分 0
发帖 3
注册 2010-12-21
状态 离线
|
『第 3 楼』:
使用 LLM 解释/回答一下
Hanyeguxing,批处理试验成功。
但是这个批处理,把要添加的文本(Txtsetup.sif)的最前、最后的空格以及文本中间的空行都删除了,可是这些我都想保留。应该怎么办呢?谢谢你的帮助。
还有,我试验了下面这个批处理,但是处理速度太慢了,不如你的快,但是这个不删除空行。请看:
……………………………………………………………………………………………………
@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
………………………………………………………………………………………
谢谢指教啊!
Last edited by mydosp on 2010-12-25 at 17:17 ]
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 ]
|
|
2010-12-25 12:37 |
|
|
Hanyeguxing
银牌会员
     正在学习中的菜鸟...
积分 1039
发帖 897
注册 2009-3-1 来自 在地狱中仰望天堂
状态 离线
|
『第 4 楼』:
使用 LLM 解释/回答一下
保留空格、空行,允许行首为;分号字符(但不允许行首为:冒号字符): @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 ]
@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 ]
|

批处理之家 http://bbs.bathome.net/forum-5-1.html |
|
2010-12-25 19:18 |
|
|
mydosp
新手上路

积分 0
发帖 3
注册 2010-12-21
状态 离线
|
『第 5 楼』:
谢谢
使用 LLM 解释/回答一下
谢谢!这个批处理很成功。我正在研究xp安装版如何定做,谢谢您对我的帮助。今后,还要向您讨教呢。
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.
|
|
2010-12-25 19:27 |
|
|