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-06-29 01:44
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » How to replace symbols in a text file with spaces? View 4,064 Replies 16
Original Poster Posted 2006-05-13 12:28 ·  中国 安徽 亳州 电信
新手上路
Credits 12
Posts 4
Joined 2006-05-13 12:08
20-year member
UID 55436
Status Offline
Thanks, using the batch processing method, the file is attached. The content is 2006|2007|2008|2009
Attachments
hhh.txt (19 bytes, Credits to download 1 pts, Downloads: 46)
Floor 2 Posted 2006-05-13 12:36 ·  中国 湖北 荆门 电信
荣誉版主
★★★
Credits 2,013
Posts 718
Joined 2006-02-18 07:07
20-year member
UID 50550
Status Offline
```
@echo off
set /p str=<hhh.txt
set str=%str:|= %
echo %str%
pause
```
Just save the content of each line into a variable and then use the set command to transform it. The given example can only operate the first line of the text file. To operate multiple lines, you can use the for command, or use the scripting.filesystemobjects object and split function of the vbs script.
Floor 3 Posted 2006-05-13 13:49 ·  中国 安徽 亳州 电信
新手上路
Credits 12
Posts 4
Joined 2006-05-13 12:08
20-year member
UID 55436
Status Offline
Thanks to the moderator for the explanation. Could you please help write a program that can handle thousands of records?

It's best to use the FOR command, something that's easy to understand, heh.

It's not that I'm lazy, I just started learning DOS commands, but there are too many used in work.

Thanks to the moderator again.
Floor 4 Posted 2006-05-13 14:01 ·  中国 安徽 亳州 电信
新手上路
Credits 12
Posts 4
Joined 2006-05-13 12:08
20-year member
UID 55436
Status Offline
Can the processed information be saved back to the original file?
Floor 5 Posted 2006-05-13 14:17 ·  中国 湖北 荆门 电信
荣誉版主
★★★
Credits 2,013
Posts 718
Joined 2006-02-18 07:07
20-year member
UID 50550
Status Offline
You can refer to the VBS script in (url=http://www.cn-dos.net/forum/viewthread.php?tid=20327), which can realize the function you need. Just enter "|:= " in the pop-up dialog box.
Floor 6 Posted 2006-05-13 14:41 ·  中国 安徽 亳州 电信
新手上路
Credits 12
Posts 4
Joined 2006-05-13 12:08
20-year member
UID 55436
Status Offline
Originally posted by 3742668 at 2006-5-13 14:17:
You can refer to the vbs script in this post, which can achieve the function you need.
Just enter "|:= &qu ... in the pop-up dialog box...

Got it, it's very good, thank you
Floor 7 Posted 2006-05-25 15:24 ·  中国 广东 深圳 电信
初级用户
Credits 82
Posts 31
Joined 2006-05-23 00:33
20-year member
UID 55824
Status Offline
It is more convenient with sed,
sed "s/a/b/g" t.txt \\Replace all characters a with character b in t.txt.
find "o" t.txt|sed "s/tt/xx/g" \\Replace the "tt" characters with character "xx" in all lines containing character "o" in the t.txt file
sed is one of the classic commands in Linux. Now it has been grafted to DOS by some experts and combined with batch processing, which is very powerful and flexible. There are also many advanced usages, and you can refer to the sed command in Linux tutorials. It is basically the same as the usage under Linux. This command is only more than 80k and can be found on the Internet.

[ Last edited by fan927 on 2006-5-25 at 15:26 ]
Floor 8 Posted 2006-05-25 19:02 ·  中国 山西 运城 中移铁通
元老会员
★★★★
Batchinger
Credits 4,432
Posts 1,512
Joined 2002-10-18 00:00
23-year member
UID 19
Gender Male
Status Offline
Re fan927:

"sed is one of the classic commands in Linux, and now some experts have ported it to DOS."

The design concept of sed should originate from the editor ed under Unix. It was a character stream editor written by Eric S. Raymond for the open-source operating system envisioned by the GNU organization around 1991. Since it is an open-source program, various ported versions for different platforms quickly appeared. And Howard Helman rewrote HHSED at that time, providing running versions for the Unix@SUN4 and DOS@PC platforms. At that time, Linux had just been born. Later, with the maturity of the POSIX standard and the realization of Linux, the GNU version of sed was applied to Linux.
※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!
Floor 9 Posted 2006-05-25 20:11 ·  中国 广东 深圳 电信
初级用户
Credits 82
Posts 31
Joined 2006-05-23 00:33
20-year member
UID 55824
Status Offline
Originally posted by willsort at 2006-5-25 19:02:
Re fan927:

"sed is one of the classic commands in Linux, and now it has been grafted to DOS by some experts"

The design concept of sed should have originated from the editor ed under Unix. Eric S. Raymond was in 1991...


Learned something new, thank you, moderator willsort.
But I don't know why such an excellent command is not available in DOS? I think its operation on characters in text can be described as "completely at will". This is exactly what batch processing lacks.
Floor 10 Posted 2006-05-25 23:05 ·  中国 山西 临汾 中移铁通
元老会员
★★★★
Batchinger
Credits 4,432
Posts 1,512
Joined 2002-10-18 00:00
23-year member
UID 19
Gender Male
Status Offline
Re fan927:

Please note the statement in floor 8: "And Howard Helman's HHSED rewritten back then provided running versions for two platforms: Unix@SUN4 and DOS@PC". That is to say, as early as 1991 when sed first appeared, there was already a version of sed for DOS. However, because it is an open-source software following the GPL, it can only exist as a third-party tool and cannot be included in Microsoft's MS-DOS/Windows distribution packages.

In addition, as GNU sed has become increasingly mature in development, its ported versions for DOS16 and Win32 platforms have become more and more powerful. So it has gradually become a de facto standard like Microsoft's software, while HHSED has gradually faded into obscurity. The reasons are, on one hand, the lack of maintenance, and on the other hand, it was originally a Mod of GNU sed.

[ Last edited by willsort on 2006-5-25 at 23:16 ]
※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!
Floor 11 Posted 2006-11-29 03:19 ·  中国 湖南 怀化 电信
初级用户
Credits 170
Posts 25
Joined 2004-11-11 00:00
21-year member
UID 33534
Gender Male
Status Offline
The meaning of `set str=%str:|= %` is: It is using the substitution function of the `set` command in batch processing. It replaces all occurrences of the `|` character in the `str` variable with a space character. So it is replacing each `|` in the content read from the `hhh.txt` file (and stored in the `str` variable) with a space.
Floor 12 Posted 2006-11-29 03:24 ·  中国 河北 廊坊 三河市 移动
金牌会员
★★★★
Credits 2,725
Posts 1,160
Joined 2006-09-23 12:00
19-year member
UID 63486
From 河北廊坊
Status Offline
Originally posted by mylovelyqq at 2006-11-29 03:19:



What does the sentence "set str=%str:|= %" mean? I really don't understand.


Replace the "|" in the variable "str" with a space
三人行,必有吾师焉。 学然后知不足,教然后知困,然后能自强也。
Floor 13 Posted 2006-11-29 03:30 ·  中国 湖南 怀化 电信
初级用户
Credits 170
Posts 25
Joined 2004-11-11 00:00
21-year member
UID 33534
Gender Male
Status Offline
Originally posted by ccwan at 2006-11-20 03:24 AM:

Replace the "|" in the variable "str" with a space



I know this is the function. What is the usage of this in set? I didn't see it in the help. Can you help me analyze this sentence? Thanks
Floor 14 Posted 2006-11-29 03:35 ·  中国 湖南 怀化 电信
初级用户
Credits 170
Posts 25
Joined 2004-11-11 00:00
21-year member
UID 33534
Gender Male
Status Offline
ccwan, you don't always make it clear and then disappear. Just a result, but where are the reasons, processes, and explanations?
Floor 15 Posted 2006-11-29 03:38 ·  中国 河北 廊坊 三河市 移动
金牌会员
★★★★
Credits 2,725
Posts 1,160
Joined 2006-09-23 12:00
19-year member
UID 63486
From 河北廊坊
Status Offline
Originally posted by mylovelyqq at 2006-11-29 03:30:

I know it's this function, what is the usage of set here? I didn't see it in the help. Can you help me analyze this sentence? Thanks.

It's in the help, on the third page. %PATH:str1=str2%
三人行,必有吾师焉。 学然后知不足,教然后知困,然后能自强也。
Forum Jump: