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-08-05 13:51
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » How to use batch processing to modify the content of a text file under DOS View 2,416 Replies 9
Original Poster Posted 2006-05-10 20:06 ·  英国
新手上路
Credits 16
Posts 4
Joined 2006-04-16 02:32
20-year member
UID 53907
Status Offline
I now only know there is a findstr command, which can only be used to find the characters to be modified, but I don't know what command to use to process after finding. I want to ask all the experts.

For example. In the DOS 7.1 English environment, to edit a.txt

Now I want to create a batch file, whose function is:
If there is a line "a=10" in the a.txt file, change 10 to 0. If there is originally "a=0", then continue with the following batch processing.
If there is a line of text "b=我", delete this line of text (this line of text is not necessarily at the end of the text, may be in the middle, but definitely occupies a single line). If there is no "b=我", then add "b=你" to a.txt (I know the append command ">>", just want to know whether it can be inserted to a specific position, such as the Nth line)

Thank you all for your efforts.

If there is no solution under pure DOS, as long as there is a solution that can have the same effect under XP SP2 or 98, it is also okay. Thanks

P.S. I am a programming novice, and I have only made small things like boot disks with batch processing myself.

[ Last edited by rx79 on 2006-5-10 at 21:13 ]
Floor 2 Posted 2006-05-11 00:36 ·  英国
新手上路
Credits 16
Posts 4
Joined 2006-04-16 02:32
20-year member
UID 53907
Status Offline
Well, I flipped through the old posts. As a result, I solved the problem by using change + if. Thanks
Floor 3 Posted 2006-05-13 22:49 ·  中国 广东 东莞 电信
初级用户
★★
Credits 118
Posts 66
Joined 2005-10-21 03:27
20-year member
UID 43827
Status Offline
Encountered the same problem. Since you solved it, post the code to enrich the forum! This is not decent.
Floor 4 Posted 2006-05-13 22:51 ·  中国 广东 东莞 电信
初级用户
★★
Credits 118
Posts 66
Joined 2005-10-21 03:27
20-year member
UID 43827
Status Offline
My question is that I once downloaded more than 400 e-novels in htm format, but the unpleasant thing is that each page contains the same advertisement code! I want to use batch processing to delete it! How to do it?
Floor 5 Posted 2006-05-15 19:39 ·  中国 江苏 苏州 电信
中级用户
★★
我是DOS学者
Credits 367
Posts 180
Joined 2006-05-14 10:53
20-year member
UID 55507
Gender Male
From 重庆
Status Offline
BAT is not that powerful either. It's not a programming language.
Floor 6 Posted 2006-05-23 15:14 ·  中国 广东 深圳 移动
初级用户
Credits 142
Posts 13
Joined 2004-07-04 00:00
22-year member
UID 27830
Gender Male
Status Offline
Using sed is more convenient, sed is very powerful
Floor 7 Posted 2006-05-30 00:17 ·  中国 湖南 益阳 电信
初级用户
Credits 28
Posts 12
Joined 2006-05-29 18:41
20-year member
UID 56212
Status Offline
Originally posted by senffon at 2006-5-13 22:51:
My problem is that I once downloaded more than 400 electronic novels in htm format, but what's annoying is that the same advertisement code is contained in each page! I want to use batch processing to delete it! How to do it?


You can use DW, find and replace the source code for the entire site. I often use it
Floor 8 Posted 2007-08-03 14:58 ·  中国 浙江 杭州 拱墅区 电信
初级用户
Credits 20
Posts 8
Joined 2007-08-02 15:19
19-year member
UID 94511
Gender Male
Status Offline
Originally posted by senffon at 2006-5-13 10:49 PM:
Encountered the same problem. Since you solved it, post the code to enrich the forum! This is not decent.



Yes. I am exactly in need of such a solution.
Floor 9 Posted 2007-08-03 18:53 ·  中国 香港 环球全域电讯
新手上路
Credits 14
Posts 5
Joined 2007-08-03 18:27
19-year member
UID 94589
Gender Female
Status Offline
Copied some experiences from predecessors, let's see if it works? :)

@echo off
call :replace my.txt aaa bbb >>my1.txt

goto :eof

:replace
setlocal ENABLEDELAYEDEXPANSION
for /f "tokens=1* delims=" %%i in (%1) do set var=%%i & echo !var:%2=%3!
endlocal
goto :eof


The above code is to replace aaa with bbb. It should work, I have tried it.
Floor 10 Posted 2007-08-03 20:15 ·  中国 陕西 西安 电信
铂金会员
★★★★
Credits 5,212
Posts 2,478
Joined 2007-02-08 23:39
19-year member
UID 79003
Gender Male
Status Offline
VBS can complete...
Forum Jump: