|
rx79
新手上路

积分 16
发帖 4
注册 2006-4-16
状态 离线
|
『楼 主』:
怎样在dos下用批处理去修改文本文件内容
使用 LLM 解释/回答一下
我现在只知道有个findstr的命令,这个只能用来找到想要修改的字符,但是找到后用什么命令处理我就不知道了,想请教各位高手。
例如。在dos7。1英文环境下,要编辑a.txt
现在我想创建一个批处理文件,其作用是:
当发现a.txt文件中存在“a=10”这行内容的话,将10修改为0,如果发现本来“a=0"的话,则继续下面的批处理。
当发现存在“b=我”的这一行文字的话,将此行文字删除(此行文字不一定在文本的最后,可能在中间,但肯定独占一行),如不存在“b=我”的话,则添加“b=你"到a.txt(追加命令我知道“〉〉”只是想知道能否添加插入到具体位置,比如第N行)
谢谢,有劳各位费心了。
如果在纯dos下没有解决方法的话,只要能在xpsp2或98下能起到同样效果的解决方法也行。感谢
P.S.本人编程盲,也只用批处理自己做过启动盘类的小玩艺。
Last edited by rx79 on 2006-5-10 at 21:13 ]
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 ]
|
|
2006-5-10 20:06 |
|
|
rx79
新手上路

积分 16
发帖 4
注册 2006-4-16
状态 离线
|
『第 2 楼』:
使用 LLM 解释/回答一下
嗯,翻了翻旧帖。结果用change+if解决问题了。
谢谢
Well, I flipped through the old posts. As a result, I solved the problem by using change + if. Thanks
|
|
2006-5-11 00:36 |
|
|
senffon
初级用户
 
积分 118
发帖 66
注册 2005-10-21
状态 离线
|
『第 3 楼』:
使用 LLM 解释/回答一下
遇到过同样问题,你既然解决了,就把代码贴出来充实一下论坛啊!这个做法不厚道啊
Encountered the same problem. Since you solved it, post the code to enrich the forum! This is not decent.
|
|
2006-5-13 22:49 |
|
|
senffon
初级用户
 
积分 118
发帖 66
注册 2005-10-21
状态 离线
|
『第 4 楼』:
使用 LLM 解释/回答一下
我的问题是,有次下了四百多部htm格式的电子小说,不过不爽的是每一页中都含有相同的广告代码!我想用批处理来删除掉!如何做?
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?
|
|
2006-5-13 22:51 |
|
|
BWSkyer
中级用户
   我是DOS学者
积分 367
发帖 180
注册 2006-5-14 来自 重庆
状态 离线
|
『第 5 楼』:
使用 LLM 解释/回答一下
BAT也没有这么强啊。。他不是编程语言。
BAT is not that powerful either. It's not a programming language.
|
|
2006-5-15 19:39 |
|
|
wind_7th
初级用户
 
积分 142
发帖 13
注册 2004-7-4
状态 离线
|
『第 6 楼』:
使用 LLM 解释/回答一下
用sed更方便,sed很强
Using sed is more convenient, sed is very powerful
|
|
2006-5-23 15:14 |
|
|
ick
初级用户
 
积分 28
发帖 12
注册 2006-5-29
状态 离线
|
『第 7 楼』:
使用 LLM 解释/回答一下
Originally posted by senffon at 2006-5-13 22:51:
我的问题是,有次下了四百多部htm格式的电子小说,不过不爽的是每一页中都含有相同的广告代码!我想用批处理来删除掉!如何做?
可以用DW,整站查找替换源码。我经常用
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
|
|
2006-5-30 00:17 |
|
|
weizhengguo
初级用户
 
积分 20
发帖 8
注册 2007-8-2
状态 离线
|
『第 8 楼』:
使用 LLM 解释/回答一下
Originally posted by senffon at 2006-5-13 10:49 PM:
遇到过同样问题,你既然解决了,就把代码贴出来充实一下论坛啊!这个做法不厚道啊
是的。我正需要这样的解决方法。
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.
|
|
2007-8-3 14:58 |
|
|
gzbbj
新手上路

积分 14
发帖 5
注册 2007-8-3
状态 离线
|
『第 9 楼』:
使用 LLM 解释/回答一下
抄袭了些前辈的经验,看看行不行?:)
@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
以上代码是把aaa替代成bbb的.应该可以,我试过了.
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.
|
|
2007-8-3 18:53 |
|
|
slore
铂金会员
      
积分 5212
发帖 2478
注册 2007-2-8
状态 离线
|
|
2007-8-3 20:15 |
|