中国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-05 14:52
48,038 topics / 350,123 posts / today 1 new / 48,251 members
DOS批处理 & 脚本技术(批处理室) » How to use batch processing to modify the content of a text file under DOS
Printable Version  2,417 / 9
Floor1 rx79 Posted 2006-05-10 20:06
新手上路 Posts 4 Credits 16
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 ]
Floor2 rx79 Posted 2006-05-11 00:36
新手上路 Posts 4 Credits 16
Well, I flipped through the old posts. As a result, I solved the problem by using change + if. Thanks
Floor3 senffon Posted 2006-05-13 22:49
初级用户 Posts 66 Credits 118
Encountered the same problem. Since you solved it, post the code to enrich the forum! This is not decent.
Floor4 senffon Posted 2006-05-13 22:51
初级用户 Posts 66 Credits 118
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?
Floor5 BWSkyer Posted 2006-05-15 19:39
中级用户 Posts 180 Credits 367 From 重庆
BAT is not that powerful either. It's not a programming language.
Floor6 wind_7th Posted 2006-05-23 15:14
初级用户 Posts 13 Credits 142
Using sed is more convenient, sed is very powerful
Floor7 ick Posted 2006-05-30 00:17
初级用户 Posts 12 Credits 28
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
Floor8 weizhengguo Posted 2007-08-03 14:58
初级用户 Posts 8 Credits 20
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.
Floor9 gzbbj Posted 2007-08-03 18:53
新手上路 Posts 5 Credits 14
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.
Floor10 slore Posted 2007-08-03 20:15
铂金会员 Posts 2,478 Credits 5,212
VBS can complete...
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023