|
synn2006
新手上路

积分 12
发帖 5
注册 2006-10-27
状态 离线
|
『楼 主』:
如何用其他文本内容覆盖某一文本指定段落的内容
使用 LLM 解释/回答一下
──────────────── 版务记录 ────────────────
执行:namejm
原标题:txt文本内容处理问题
修改后标题:如何用其他文本内容覆盖某一文本指定段落的内容
说明:因原标题过于模糊,不便于论坛的搜索和管理,在本提示发表三日之后,
楼主尚未更改标题,现由本人强制修改标题,并扣除楼主2点积分。
──────────────── 版务记录 ────────────────
有a.txt和b.txt两个文件(内容纯属虚构,但足以表达我的意思):
a.txt内容如下:
:
monday
:
yang li
wang yu
shan liang
:
meeting
study
b.txt的内容如下:
zhou zhuo
tian li
shang xiao nan
sun chao
能不能用一个bat实现如下功能:
每次先删除a.txt中:后面的所有人名,然后把b.txt中的人名内容加到其中,使其变成如下显示:
a.txt:
:
monday
:
zhou zhuo
tian li
shang xiao nan
sun chao
:
meeting
study
以后b中的内容可能总是会变,我只是想一执行bat,就把它们都导入a.txt中的name 后面。
如果bat实现不了这种操作,能不能告诉我用vbs怎么编写?
另外还有一个问题,如何在批处理文件中启动执行一个vbs呢?
期待大家的回答,thanks in advance!!!!!!!!!!!!!!!!!!!!!
Last edited by namejm on 2007-1-25 at 01:00 PM ]
──────────────── Moderation Record ────────────────
Performed by: namejm
Original title: txt text content processing problem
Modified title: How to overwrite the content of a specified paragraph in a text with other text content
Description: Because the original title was too vague, it was not convenient for forum search and management. Three days after this notice was posted,
the original poster had not changed the title, so I forcibly changed the title and deducted 2 points from the original poster.
──────────────── Moderation Record ────────────────
There are two files, a.txt and b.txt (the content is purely fictional, but it is enough to express my meaning):
The content of a.txt is as follows:
:
monday
:
yang li
wang yu
shan liang
:
meeting
study
The content of b.txt is as follows:
zhou zhuo
tian li
shang xiao nan
sun chao
Can a bat be used to achieve the following function:
Each time first delete all the names after : in a.txt, and then add the name content in b.txt to it, so that it becomes as follows:
a.txt:
:
monday
:
zhou zhuo
tian li
shang xiao nan
sun chao
:
meeting
study
The content in b may always change in the future, I just want to execute the bat, and import them all after name in a.txt.
If the bat cannot achieve this operation, can you tell me how to write it in vbs?
In addition, there is another question, how to start and execute a vbs in a batch file?
Looking forward to everyone's answers, thanks in advance!!!!!!!!!!!!!!!!!!!!!
Last edited by namejm on 2007-1-25 at 01:00 PM ]
|
|
2006-10-28 03:00 |
|
|
无奈何
荣誉版主
      
积分 1338
发帖 356
注册 2005-7-15
状态 离线
|
    『第 2 楼』:
使用 LLM 解释/回答一下
试试这个命令,写在一行有点长。
sed -e "/\:/,/\:/{/^ */d}" -e "/\:/rb.txt" a.txt
sed 下载地址:http://www.student.northpark.edu/pemente/sed/gsed407x.zip
Try this command, it's a bit long written in one line.
sed -e "/\:/,/\:/{/^ */d}" -e "/\:/rb.txt" a.txt
Sed download address: http://www.student.northpark.edu/pemente/sed/gsed407x.zip
此帖被 +10 点积分 点击查看详情 评分人:【 redtek 】 | 分数: +10 | 时间:2006-10-28 05:17 |
|
|

☆开始\运行 (WIN+R)☆
%ComSpec% /cset,=何奈无── 。何奈可无是原,事奈无做人奈无&for,/l,%i,in,(22,-1,0)do,@call,set/p= %,:~%i,1%<nul&ping/n 1 127.1>nul
|
|
2006-10-28 04:34 |
|
|
不得不爱
超级版主
         我爱DOS
积分 5310
发帖 2044
注册 2005-9-26 来自 四川南充
状态 离线
|
|
2006-10-28 04:45 |
|
|
lxmxn
版主
       
积分 11386
发帖 4938
注册 2006-7-23
状态 离线
|
『第 4 楼』:
使用 LLM 解释/回答一下
这个是 sed 命令的错误提示。是语法错误了吧。。
This is an error message from the sed command. It's a syntax error, right?
|
|
2006-10-28 04:55 |
|
|
不得不爱
超级版主
         我爱DOS
积分 5310
发帖 2044
注册 2005-9-26 来自 四川南充
状态 离线
|
|
2006-10-28 04:55 |
|
|
不得不爱
超级版主
         我爱DOS
积分 5310
发帖 2044
注册 2005-9-26 来自 四川南充
状态 离线
|
|
2006-10-28 04:56 |
|
|
无奈何
荣誉版主
      
积分 1338
发帖 356
注册 2005-7-15
状态 离线
|
『第 7 楼』:
使用 LLM 解释/回答一下
Re qwe1234567
这是错误提示,老兄换个高版本的再试一下,把二楼的链接下下来。
Re qwe1234567
This is an error message. Dude, try with a higher version and download the link on the second floor.
|

☆开始\运行 (WIN+R)☆
%ComSpec% /cset,=何奈无── 。何奈可无是原,事奈无做人奈无&for,/l,%i,in,(22,-1,0)do,@call,set/p= %,:~%i,1%<nul&ping/n 1 127.1>nul
|
|
2006-10-28 04:57 |
|
|
lxmxn
版主
       
积分 11386
发帖 4938
注册 2006-7-23
状态 离线
|
『第 8 楼』:
使用 LLM 解释/回答一下
要查看帮助还要这样打才行:"sed -h"
To view the help, you need to type like this: "sed -h"
|
|
2006-10-28 05:00 |
|
|
无奈何
荣誉版主
      
积分 1338
发帖 356
注册 2005-7-15
状态 离线
|
『第 9 楼』:
使用 LLM 解释/回答一下
一会儿好几贴了,没有看到你们先前的回复。我晕,我以为用老的版本运行出现的错误提示呢。不过老的版本 sed 302 运行确实有问题,得小改动一下。
sed -e "/\:/,/\:/{/^ */d;}" -e "/\:/rb.txt" a.txt
A while ago there were several posts, but I didn't see your previous replies. Oh my, I thought it was an error message from running the old version. But indeed, there is a problem with the old version sed 302, and a small change is needed.
sed -e "/\:/,/\:/{/^ */d;}" -e "/\:/rb.txt" a.txt
|

☆开始\运行 (WIN+R)☆
%ComSpec% /cset,=何奈无── 。何奈可无是原,事奈无做人奈无&for,/l,%i,in,(22,-1,0)do,@call,set/p= %,:~%i,1%<nul&ping/n 1 127.1>nul
|
|
2006-10-28 05:16 |
|
|
redtek
金牌会员
     
积分 2902
发帖 1147
注册 2006-9-21
状态 离线
|
『第 10 楼』:
使用 LLM 解释/回答一下
这个太强大了,欣赏~:)
This is too powerful, admire it~:)
|

Redtek,一个永远在网上流浪的人……
_.,-*~'`^`'~*-,.__.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._ |
|
2006-10-28 05:17 |
|
|
namejm
荣誉版主
       batch fan
积分 5226
发帖 1737
注册 2006-3-10 来自 成都
状态 离线
|
『第 11 楼』:
使用 LLM 解释/回答一下
如果非得用批处理来解决不可的话,可以试试下面的代码(如果a.txt中的行数量十分巨大的话,速度将会比较慢):
@echo off
cd.>test.txt
for /f "tokens=1* delims=:" %%i in ('findstr /n . a.txt') do (
if not "%%j"==":" (>>test.txt echo %%j) else (
set line=%%i&goto insert
)
)
:insert
>>test.txt echo :
>>test.txt type b.txt
>>test.txt echo.
set flag=1
for /f "skip=%line% delims=" %%i in (a.txt) do (
if "%%i"==":" set flag=
if not defined flag >>test.txt echo %%i
)
)
start test.txt
Last edited by namejm on 2007-1-25 at 12:54 PM ]
If you have to use batch processing to solve it, you can try the following code (if the number of lines in a.txt is extremely large, the speed will be relatively slow):
@echo off
cd.>test.txt
for /f "tokens=1* delims=:" %%i in ('findstr /n . a.txt') do (
if not "%%j"==":" (>>test.txt echo %%j) else (
set line=%%i&goto insert
)
)
:insert
>>test.txt echo :
>>test.txt type b.txt
>>test.txt echo.
set flag=1
for /f "skip=%line% delims=" %%i in (a.txt) do (
if "%%i"==":" set flag=
if not defined flag >>test.txt echo %%i
)
)
start test.txt
Last edited by namejm on 2007-1-25 at 12:54 PM ]
|

尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。 |
|
2006-10-28 05:50 |
|
|
synn2006
新手上路

积分 12
发帖 5
注册 2006-10-27
状态 离线
|
『第 12 楼』:
使用 LLM 解释/回答一下
谢谢大家的帮助,我知道啦~~~
Thank you everyone for your help, I understand now~~~
|
|
2006-10-29 23:07 |
|