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-22 00:03
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Question: Organize the text (newcomers and veterans are all welcome to try) View 6,073 Replies 54
Floor 31 Posted 2008-07-14 16:27 ·  美国 惠普HP
版主
★★★★★
Credits 9,023
Posts 5,017
Joined 2007-05-31 19:39
19-year member
UID 89899
Gender Male
Status Offline
```
change a.txt /from "&H0D0A" /to null
change a.txt /from "。" /to "。&H0D0A0D0A"
```

change.exe
http://upload.cn-dos.net/img/427.zip

[ Last edited by HAT on 2008-10-29 at 14:19 ]
Floor 32 Posted 2008-07-14 17:21 ·  中国 湖南 娄底 电信
银牌会员
★★★
Credits 2,268
Posts 879
Joined 2006-12-19 16:23
19-year member
UID 73968
Gender Male
Status Offline
The idea of building block 31 is also to concatenate a.txt into one line first and then replace. The test is still not working. I just downloaded a change and tried it.
Ask a question: How to represent lines that do not include a certain character in change?
致精致简!
Floor 33 Posted 2008-07-14 17:34 ·  中国 山西 电信
银牌会员
★★★
天的白色影子
Credits 2,343
Posts 636
Joined 2004-03-06 00:00
22-year member
UID 19350
Gender Male
Status Offline
It seems there's no problem. How come it doesn't work?
change is not sed
There aren't so many regular expression markers
As for the lines that don't contain the specified character
There is a /v switch
Similar to find

[ Last edited by qzwqzw on 2008-7-14 at 05:41 PM ]
Floor 34 Posted 2008-07-14 17:39 ·  中国 山西 电信
银牌会员
★★★
天的白色影子
Credits 2,343
Posts 636
Joined 2004-03-06 00:00
22-year member
UID 19350
Gender Male
Status Offline
Oh, I see.

Didn't you notice that change is a program for DOS?

To run it under the win32 console cmd, you need to initialize the Chinese environment first.

chcp 437>nul & graftabl 936>nul
Floor 35 Posted 2008-07-14 17:44 ·  中国 湖南 娄底 电信
银牌会员
★★★
Credits 2,268
Posts 879
Joined 2006-12-19 16:23
19-year member
UID 73968
Gender Male
Status Offline
Originally posted by qzwqzw at 2008-7-14 17:39:
Oh, I understand.

Did you not notice that change is a program for DOS?

To run it under the win32 console cmd, you need to initialize the Chinese environment first.

chcp 437>nul & graftabl 936>nul

It is indeed this problem, thank you!
But I still want to ask, how to represent the lines that do not include a certain character in change?
My idea is to first replace all periods with carriage returns, and then delete the carriage returns of all lines that do not contain periods
致精致简!
Floor 36 Posted 2008-07-14 17:59 ·  中国 湖南 娄底 电信
银牌会员
★★★
Credits 2,268
Posts 879
Joined 2006-12-19 16:23
19-year member
UID 73968
Gender Male
Status Offline
Is there a tutorial for change.exe? The help information is in English and I can't understand any of it...
致精致简!
Floor 37 Posted 2008-07-14 18:04 ·  美国 惠普HP
版主
★★★★★
Credits 9,023
Posts 5,017
Joined 2007-05-31 19:39
19-year member
UID 89899
Gender Male
Status Offline
I have a part of Chinese help, incomplete.

CHANGE.EXE is a command-line tool for processing file modifications. The target file can be of any size and any format. It can execute 30 commands at a time! Very efficient.

I. Basic format:
change source file.txt /from "string to be replaced" /to "replacement string" /in "condition"

II. The known limitation is that it does not support long names and may not recognize some special characters in Windows as file names. The solution is to access with the short file name (for example: myfile~1.txt).

III. Detailed function list:
1. The processed file is not limited in size, provided that there is at least the same amount of reserved space on the disk as the target file for temporarily storing its copy;
2. It can handle not only text files but also binary files;
3. The lengths of the substituted and replaced strings can be different;
4. The replacement behavior can be specified to occur only in specific lines. The mark of the specific line is that another specified character (string) appears. This string also allows case sensitivity;
5. Up to 30 modification instructions can be executed simultaneously;
6. Supports subdirectories;
7. Compatible with dos/Unix/Mac text formats;
8. The input and output strings can be text (Ascii), or hexadecimal values or decimal values;
9. The replacement speed is extremely fast;
10. Has a backup option in case the source file may be damaged;
11. The replacement work can be carried out interactively (console);
12. In addition to the command line and console, it also allows combining multiple instructions into a control file for execution at one time;
13. Boolean variables can be used;
14. The source file name supports wildcards;
15. "*" when specified in the string to be modified means the entire substring from the current position to the end of the line;
16. When specifying the target string, the "column" can be set, and the replacement will only occur when the character is within this range;
17. Files can be excluded from processing according to file attributes;
18. Some lines can be excluded from processing;
19. Pressing ESC can abort the processing process.
20.

IV. How to specify parameters
When the program runs, it will read parameters in the following three ways:
1. INI file
2. System environment variables
3. Command line
First look at the most commonly used command line syntax.
To/From/In specification:
FROM text to be replaced
TO text for replacement
TO (optional) specify the specific line mark where the replacement behavior occurs
For example, suppose the test.txt file contains the following two lines:
The quick brown fox jumped over
the lazy brown dog.

We enter:
change /from brown /to red /fox
Then the file becomes:
The quick red fox jumped over
the lazy brown dog.
That is: the "brown" in the line where "fox" appears is replaced with "red", and other lines remain unchanged.

If the specified string contains spaces or other special characters, use double quotes, for example:
CHANGE test.TXT /FROM "my music" /TO "my video"

Or use hexadecimal characters to handle special characters, such as:
CHANGE test.TXT /FROM &H0D0A0D0A /TO &H0D0A
(Delete redundant lines)

Example of setting column width:
change test.txt /from ok 5/10 /to no
Only replace ok from column 5 to column 10 with no. This function recognizes the position according to the first character. For example, if there is an "ok" in columns 4 and 5, it will not be replaced.

Example of only deleting:
change test.txt /from no /to null
(That is: delete all no)

If you want to ignore the case of English letters, use the parameter /I

Similar to DOS, you can use the parameter /s to handle the replacement work of files in all subdirectories

Example of replacing specified lines:
change test.txt /from no /to re /lines 3-8 30-50
(That is: only replace the characters in lines 3 to 8 and 30 to 50)

For security purposes, the program always automatically generates a temporary file to back up the source file. If another output file is specified with the /N file name parameter, there will be no temporary file output.

To eliminate extra spaces at the end of the file, use the parameter /trim

Example of using Boolean variables:
CHANGE TEST.TXT /FROM Apple /TO Banana /IN (red OR brown) AND NOT Pear
Will replace apple with banana, but the line must have red or brown appear, and Pear does not appear

The meaning of the return error code of this program:
0 No error, modified
1 No error, no modification
253 Aborted in advance
254 Internal error
255 Syntax error
Floor 38 Posted 2008-07-14 18:05 ·  美国 惠普HP
版主
★★★★★
Credits 9,023
Posts 5,017
Joined 2007-05-31 19:39
19-year member
UID 89899
Gender Male
Status Offline
//But I still want to ask, how to represent the lines that do not include a certain character in change?

/V says to find those items that do NOT match the specification;
Floor 39 Posted 2008-07-14 18:14 ·  中国 湖南 娄底 电信
银牌会员
★★★
Credits 2,268
Posts 879
Joined 2006-12-19 16:23
19-year member
UID 73968
Gender Male
Status Offline
Thanks, the Chinese help information I got is also like this, too little.
change a.txt /from "&H0D0A" /to "yyy&H0D0A"  /in 。

My original intention was to replace the carriage return of the line containing the full stop with yyy plus carriage return, but why did the lines without full stops also add yyy at the end???
致精致简!
Floor 40 Posted 2008-07-14 19:10 ·  中国 山西 电信
银牌会员
★★★
天的白色影子
Credits 2,343
Posts 636
Joined 2004-03-06 00:00
22-year member
UID 19350
Gender Male
Status Offline
Indeed, that's the problem. Thanks!

But I still want to ask, how to represent lines that do not include a certain character in change?

My idea is to first replace all periods with carriage returns, and then delete the carriage returns of all lines that do not contain periods.
--------------------
Really very meticulous
Since there is already a suitable solution
Why go for the difficult instead of the easy?

Change has two working modes
One is binary (block) mode
That is, the full-text replacement I mentioned
Read bytes in blocks and then perform replacement
Treat 0d0a as ordinary bytes

The other is text (record) mode
That is, the line buffering mode I mentioned
Read text by line and then perform replacement
Special processing will be done for 0d0a

And if &H hexadecimal characters are used in /from /to /in
Then it directly enters binary mode
And the /in switch requires the support of text mode
So your replacement operation is invalid

The following command is an example
change \test\a.txt /n\test\b.txt /from "文件" /to "file" /in not "File"
Floor 41 Posted 2008-07-14 19:17 ·  中国 湖南 娄底 电信
银牌会员
★★★
Credits 2,268
Posts 879
Joined 2006-12-19 16:23
19-year member
UID 73968
Gender Male
Status Offline
Thanks, thanks a lot, got quite a few gains again... ^_^
致精致简!
Floor 42 Posted 2008-07-14 19:34 ·  中国 重庆 九龙坡区 电信
版主
★★★★★
Credits 9,023
Posts 5,017
Joined 2007-05-31 19:39
19-year member
UID 89899
Gender Male
Status Offline
The explanation of qzwqzw is really detailed ah ^_^
Floor 43 Posted 2008-07-14 23:25 ·  中国 湖南 娄底 电信
银牌会员
★★★
Credits 2,268
Posts 879
Joined 2006-12-19 16:23
19-year member
UID 73968
Gender Male
Status Offline
It's really frustrating. Why can't I run brother qzwqzw's sample code?

My test code is as follows: xp sp2
:

@echo off
chcp 437>nul & graftabl 936>nul
change \test\a.txt /n \test\c.txt /from "一" /to " yyy " /in not "。"

The understanding of this code is:
Run in test mode, that is, read line by line. No temporary file is generated, the new file is in c.txt,
Replace "一" with " yyy " in the lines that do not contain full stops
致精致简!
Floor 44 Posted 2008-07-15 00:16 ·  中国 江西 南昌 电信
银牌会员
★★★
天的白色影子
Credits 2,343
Posts 636
Joined 2004-03-06 00:00
22-year member
UID 19350
Gender Male
Status Offline
Oh!
test is the relative path of my own sample text file
not a pattern

Do not put spaces after /n
Floor 45 Posted 2008-07-15 13:34 ·  中国 湖南 娄底 电信
银牌会员
★★★
Credits 2,268
Posts 879
Joined 2006-12-19 16:23
19-year member
UID 73968
Gender Male
Status Offline
It seems it's determined to bully me. I've tested like this too, still no good

@echo off
cd.>d\c.txt
chcp 437>nul & graftabl 936>nul
change \d\a.txt /n\d\c.txt /from "一" /to " yyy " /in not "。"


[ Last edited by 26933062 on 2008-7-15 at 01:35 PM ]
致精致简!
Forum Jump: