![]() |
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-25 23:08 |
47,812 topics / 349,910 posts / today 0 new / 48,264 members |
| DOS批处理 & 脚本技术(批处理室) » How to replace symbols in a text file with spaces? |
| Printable Version 4,289 / 16 |
| Floor1 hhihh | Posted 2006-05-13 12:28 |
| 新手上路 Posts 4 Credits 12 | |
|
Thanks, using the batch processing method, the file is attached. The content is 2006|2007|2008|2009
Attachments hhh.txt (19 bytes) |
|
| Floor2 3742668 | Posted 2006-05-13 12:36 |
| 荣誉版主 Posts 718 Credits 2,013 | |
|
```
@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. |
|
| Floor3 hhihh | Posted 2006-05-13 13:49 |
| 新手上路 Posts 4 Credits 12 | |
|
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. |
|
| Floor4 hhihh | Posted 2006-05-13 14:01 |
| 新手上路 Posts 4 Credits 12 | |
|
Can the processed information be saved back to the original file?
|
|
| Floor5 3742668 | Posted 2006-05-13 14:17 |
| 荣誉版主 Posts 718 Credits 2,013 | |
|
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.
|
|
| Floor6 hhihh | Posted 2006-05-13 14:41 |
| 新手上路 Posts 4 Credits 12 | |
Originally posted by 3742668 at 2006-5-13 14:17: Got it, it's very good, thank you |
|
| Floor7 fan927 | Posted 2006-05-25 15:24 |
| 初级用户 Posts 31 Credits 82 | |
|
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 ] |
|
| Floor8 willsort | Posted 2006-05-25 19:02 |
| 元老会员 Posts 1,512 Credits 4,432 | |
|
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. |
|
| Floor9 fan927 | Posted 2006-05-25 20:11 |
| 初级用户 Posts 31 Credits 82 | |
Originally posted by willsort at 2006-5-25 19:02: 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. |
|
| Floor10 willsort | Posted 2006-05-25 23:05 |
| 元老会员 Posts 1,512 Credits 4,432 | |
|
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 ] |
|
| Floor11 mylovelyqq | Posted 2006-11-29 03:19 |
| 初级用户 Posts 25 Credits 170 | |
|
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.
|
|
| Floor12 ccwan | Posted 2006-11-29 03:24 |
| 金牌会员 Posts 1,160 Credits 2,725 From 河北廊坊 | |
Originally posted by mylovelyqq at 2006-11-29 03:19: Replace the "|" in the variable "str" with a space |
|
| Floor13 mylovelyqq | Posted 2006-11-29 03:30 |
| 初级用户 Posts 25 Credits 170 | |
Originally posted by ccwan at 2006-11-20 03:24 AM: 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 |
|
| Floor14 mylovelyqq | Posted 2006-11-29 03:35 |
| 初级用户 Posts 25 Credits 170 | |
|
ccwan, you don't always make it clear and then disappear. Just a result, but where are the reasons, processes, and explanations?
|
|
| Floor15 ccwan | Posted 2006-11-29 03:38 |
| 金牌会员 Posts 1,160 Credits 2,725 From 河北廊坊 | |
Originally posted by mylovelyqq at 2006-11-29 03:30: It's in the help, on the third page. %PATH:str1=str2% |
|
| 1 2 Next |
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |