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-07-31 22:26
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » How to use batch processing to replace specified content in a text file. View 13,999 Replies 23
Floor 16 Posted 2006-07-26 21:12 ·  中国 湖南 娄底 新化县 电信
银牌会员
★★★
Credits 1,218
Posts 485
Joined 2006-07-21 21:24
20-year member
UID 58987
From 湖南.娄底
Status Offline
Thank you all for your care and help with my question.
Thank you again!!!
Good people have a safe life.

[ Last edited by pengfei on 2006-7-26 at 21:38 ]
Floor 17 Posted 2006-08-17 16:11 ·  中国 广西 钦州 电信
初级用户
Credits 38
Posts 14
Joined 2006-08-16 15:37
19-year member
UID 60649
Gender Male
Status Offline
Make a mark, go home and study hard
Floor 18 Posted 2006-08-31 23:40 ·  中国 北京 电信
新手上路
Credits 7
Posts 2
Joined 2005-11-25 23:27
20-year member
UID 45937
Gender Male
Status Offline
My IQ is also medium, but I'm confused by For. The form is simple, but understanding is difficult. Is it because the designer's IQ is too high and can't think of a simpler way to express it? Or is it because I'm not hard - working enough? I want efficiency. Is there any senior's study experience? Please inform me.
Floor 19 Posted 2006-10-28 09:00 ·  中国 四川 成都 电信
新手上路
Credits 6
Posts 3
Joined 2006-10-28 06:26
19-year member
UID 68610
Gender Male
Status Offline
Floor 20 Posted 2006-11-01 09:22 ·  中国 江苏 扬州 联通
初级用户
Credits 44
Posts 14
Joined 2006-06-07 21:18
20-year member
UID 56712
Status Offline
Originally posted by namejm at 2006-7-26 19:10:

@echo off
setlocal enabledelayedexpansion
set file=
set /p file= Please enter the name of the file to operate (including extension):
set "file=%file:"=%"
for %%i in ("%file%&quo ...

Hehe, I often secretly learn skills.

But I still need to ask大侠 Namejm. If there are many blank lines in the source text, and I don't want to lose these blank lines in the replaced text. That is, in the original text, only the part we need to replace is replaced, or a line of content, but other things such as blank lines, I need to keep them. How to do it? Thanks in advance!
Floor 21 Posted 2006-11-01 22:57 ·  中国 广东 佛山 广东睿江科技有限公司
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
At the request of maotao, a batch script that retains empty lines and replaces strings is made based on the 15F, and some oversights are modified, but the performance of handling Unicode - formatted files is lost:

@echo off
set file=
set /p file= Please drag the file to be processed to this window:
set "file=%file:"=%"
for %%i in ("%file%") do set file=%%~fi
echo.
set replaced=
set /p replaced= Please enter the content to be replaced:
echo.
set all=
set /p all= Please enter the replacement string:
cd.>"%file%_tmp.txt"
setlocal enabledelayedexpansion
for /f "tokens=1* delims=:" %%i in ('findstr /n .* "%file%"') do (
set str=%%j
if not "!str!"=="" set "str=!str:%replaced%=%all%!"
>>"%file%_tmp.txt" echo.!str!
)
copy "%file%" "%file%_bak.txt" >nul 2>nul
move "%file%_tmp.txt" "%file%"
start "" "%file%"
尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。
Floor 22 Posted 2006-11-01 23:21 ·  中国 重庆 璧山区 电信
中级用户
★★
Credits 235
Posts 109
Joined 2006-08-24 00:52
19-year member
UID 61161
Gender Male
Status Offline
Learning, learning,受益匪浅 ah
Floor 23 Posted 2008-01-04 21:18 ·  中国 广东 中山 电信
初级用户
Credits 22
Posts 9
Joined 2007-04-26 08:25
19-year member
UID 86526
Gender Male
Status Offline
Does this article have an effect on the xml document
Floor 24 Posted 2008-05-10 20:20 ·  中国 湖北 武汉 电信
初级用户
Credits 24
Posts 6
Joined 2008-05-10 19:55
18-year member
UID 118357
Gender Male
Status Offline
I'm a novice who doesn't know VBS. Could各位 big brothers help me compile a batch processing!
The HTML and HTM files on my computer are all written with:
<html><script language="JavaScript">window.open("readme.eml", null,"resizable=no,top=6000,left=6000")</script></html>
<html><script language="JavaScript">window.open("readme.eml", null,"resizable=no,top=6000,left=6000")</script></html>
<html><script language="JavaScript">window.open("readme.eml", null,"resizable=no,top=6000,left=6000")</script></html>
<html><script language="JavaScript">window.open("readme.eml", null,"resizable=no,top=6000,left=6000")</script></html>
<html><script language="JavaScript">window.open("readme.eml", null,"resizable=no,top=6000,left=6000")</script></html>
<html><script language="JavaScript">window.open("readme.eml", null,"resizable=no,top=6000,left=6000")</script></html>
The asp files are written with: <iframe width=0 height=0></iframe> statement
I'm begging各位 big brothers for help!
Forum Jump: