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-07 21:21
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » How to overwrite the content of a specified paragraph of a text with other text content View 2,651 Replies 11
Original Poster Posted 2006-10-28 03:00 ·  中国 北京 鹏博士BGP
新手上路
Credits 12
Posts 5
Joined 2006-10-27 21:46
19-year member
UID 68526
Gender Female
Status Offline

──────────────── 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 ]
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
namejm -2 2007-01-26 01:59
Floor 2 Posted 2006-10-28 04:34 ·  中国 浙江 宁波 鹏博士宽带
荣誉版主
★★★
Credits 1,338
Posts 356
Joined 2005-07-15 12:09
20-year member
UID 40733
Gender Male
Status Offline
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
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
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

Floor 3 Posted 2006-10-28 04:45 ·  中国 四川 南充 电信
超级版主
★★★★
我爱DOS
Credits 5,310
Posts 2,044
Joined 2005-09-26 12:00
20-year member
UID 42843
Gender Male
From 四川南充
Status Offline
The meaning of "sed: -e expression #1, char 2: Unterminated address regex" is: In the sed command, in the first expression, at the 2nd character position, there is an unclosed address regular expression.
Floor 4 Posted 2006-10-28 04:55 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
19-year member
UID 59080
Status Offline

  This is an error message from the sed command. It's a syntax error, right?
Floor 5 Posted 2006-10-28 04:55 ·  中国 四川 南充 电信
超级版主
★★★★
我爱DOS
Credits 5,310
Posts 2,044
Joined 2005-09-26 12:00
20-year member
UID 42843
Gender Male
From 四川南充
Status Offline
Floor 6 Posted 2006-10-28 04:56 ·  中国 四川 南充 电信
超级版主
★★★★
我爱DOS
Credits 5,310
Posts 2,044
Joined 2005-09-26 12:00
20-year member
UID 42843
Gender Male
From 四川南充
Status Offline
Floor 7 Posted 2006-10-28 04:57 ·  中国 浙江 宁波 鹏博士宽带
荣誉版主
★★★
Credits 1,338
Posts 356
Joined 2005-07-15 12:09
20-year member
UID 40733
Gender Male
Status Offline
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

Floor 8 Posted 2006-10-28 05:00 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
19-year member
UID 59080
Status Offline

To view the help, you need to type like this: "sed -h"
Floor 9 Posted 2006-10-28 05:16 ·  中国 浙江 宁波 鹏博士宽带
荣誉版主
★★★
Credits 1,338
Posts 356
Joined 2005-07-15 12:09
20-year member
UID 40733
Gender Male
Status Offline
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

Floor 10 Posted 2006-10-28 05:17 ·  中国 北京 联通
金牌会员
★★★★
Credits 2,902
Posts 1,147
Joined 2006-09-21 12:00
19-year member
UID 63324
Gender Male
Status Offline
This is too powerful, admire it~:)
    Redtek,一个永远在网上流浪的人……

_.,-*~'`^`'~*-,.__.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._
Floor 11 Posted 2006-10-28 05:50 ·  中国 广东 佛山 广东睿江科技有限公司
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
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没商量。
考虑问题复杂化,解决问题简洁化。
Floor 12 Posted 2006-10-29 23:07 ·  中国 北京 电信
新手上路
Credits 12
Posts 5
Joined 2006-10-27 21:46
19-year member
UID 68526
Gender Female
Status Offline
Thank you everyone for your help, I understand now~~~
Forum Jump: