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 15:26
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Please describe the specific operation environment and relevant tools you are using, such as using which programming language, which text processing tools etc. Because the content of the problem is relatively general, without specific context, it is difficult to give a precise translation and corresponding solution. If you are using a programming language like Python, you can use file reading and writing operations to achieve. For example, in Python: ```python with open('file.txt', 'r') as f: lines = f.readlines() target_line_number = 2 # Suppose to modify the 3rd line (index starts from 0) new_content = 'The content you need' lines[target_line_number - 1] = new_content + '\n' with open('file.txt', 'w') as f: f.writelines(lines) ``` But this is just a general example. If you are using other environments, the specific implementation will be different. So please provide more specific information. 请描述您使用的具体操作环境和相关工具,比如使用哪种编程语言、哪种文本处理工具等,因为问题内容比较笼统,没有具体上下文,很难给出精准的翻译和对应解决方案。如果您使用Python这类编程语言,可通过文件读写操作实现,例如Python中: ```python with open('file.txt', 'r') as f: lines = f.readlines() target_line_number = 2 # 假设修改第3行(索引从0开始) new_content = '您需要的内容' lines[target_line_number - 1] = new_content + '\n' with open('file.txt', 'w') as f: f.writelines(lines) ``` 但这只是通用示例,若使用其他环境,具体实现会不同。所以请提供更具体信息。 Please describe the specific operation environment and relevant tools you are using, such as using which programming language, which text processing tools etc. Because the content of the problem is relatively general, without specific context, it is difficult to give a precise translation and corresponding solution. If you are using a programming language like Python, you can use file reading and writing operations to achieve. For example, in Python: ```python with open('file.txt', 'r') as f: lines = f.readlines() target_line_number = 2 # Suppose to modify the 3rd line (index starts from 0) new_content = 'The content you need' lines[target_line_number - 1] = new_content + '\n' with open('file.txt', 'w') as f: f.writelines(lines) ``` But this is just a general example. If you are using other environments, the specific implementation will be different. So please provide more specific information. Please describe the specific operation environment and relevant tools you are using, such as using which programming language, which text processing tools etc. Because the content of the problem is relatively general, without specific context, it is difficult to give a precise translation and corresponding solution. If you are using a programming language like Python, you can use file reading and writing operations to achieve. For example, in Python: ```python with open('file.txt', 'r') as f: lines = f.readlines() target_line_number = 2 # Suppose to modify the 3rd line (index starts from 0) new_content = 'The content you need' lines[target_line_number - 1] = new_content + '\n' with open('file.txt', 'w') as f: f.writelines(lines) ``` But this is just a general example. If you are using other environments, the specific implementation will be different. So please provide more specific information. To convert a specific line of text in a file to the text you need, the specific implementation depends on the programming language and tools you are using. For example, if using Python, you can use the following steps: ### Step 1: Read the file Open the file in read mode and read all lines into a list. ```python with open('your_file.txt', 'r') as file: lines = file.readlines() ``` ### Step 2: Locate the line to modify Identify the line number you want to modify (note that list indices start from 0). For example, if you want to modify the 3rd line, the index is 2. ```python target_line_index = 2 # Modify the 3rd line new_line_content = 'The content you want' ``` ### Step 3: Update the line Replace the content of the specified line in the list. ```python lines[target_line_index] = new_line_content + '\n' # Add a newline character ``` ### Step 4: Write the modified content back to the file Open the file in write mode and write the modified list of lines back to the file. ```python with open('your_file.txt', 'w') as file: file.writelines(lines) ``` If you are using other programming languages or tools, the basic idea is similar, but the specific syntax will be different. For example, in Java, you can read the file line by line, modify the specified line, and then write the modified content back to the file. View 5,394 Replies 16
Original Poster Posted 2005-12-07 13:04 ·  中国 台湾 中华电信(HiNet)数据中心
初级用户
★★
Credits 154
Posts 54
Joined 2005-09-25 01:53
20-year member
UID 42804
Status Offline
If there is a file Try.txt with the following content


AAA = 10.7
BBB = 11.6
CCC = 13.4
DDD = 15.8
EEE = 17.1

If you want to use a batch file to replace the line
"CCC    = 13.4" 

with
"CCC    = 55.33" 

How should this be written

Thank you
Floor 2 Posted 2005-12-11 10:57 ·  中国 台湾 新北市 中华电信
初级用户
★★
Credits 154
Posts 54
Joined 2005-09-25 01:53
20-year member
UID 42804
Status Offline
This problem should be encountered by quite a few people
Or is it needed
Is it too simple or unsolvable ah
No news at all @@
Floor 3 Posted 2005-12-11 11:29 ·  加拿大 Bell
系统支持
★★★★★★
“新DOS时代”站长
Credits 27,736
Posts 10,521
Joined 2002-10-09 12:00
23-year member
UID 9
Status Offline
Are third-party tools allowed? If allowed, you can try tools like XCHANGE, which can be solved in one line. For example, try this command (XCHANGE is in the attachment):

XCHANGE Try.txt "CCC = 13.4" "CCC = 55.33"
Attachments
XCHANGE.EXE (22.04 KiB, Credits to download 1 pts, Downloads: 94)
Wengier - 新DOS时代

欢迎大家来到我的“新DOS时代”网站,里面有各类DOS软件和资料,地址:
http://wendos.mycool.net/

E-Mail & MSN: wengierwu AT hotmail.com (最近比较忙,有事请联系DOSroot和雨露,谢谢!)

Floor 4 Posted 2005-12-11 14:30 ·  中国 福建 泉州 电信
初级用户
Credits 51
Posts 14
Joined 2005-11-06 20:02
20-year member
UID 44706
Gender Male
Status Offline
Is there a detailed application explanation of this tool?
Floor 5 Posted 2006-01-12 20:18 ·  中国 甘肃 兰州 电信
初级用户
Credits 90
Posts 38
Joined 2006-01-06 18:41
20-year member
UID 48522
Status Offline
```@echo off & setlocal EnableDelayedExpansion
echo.>n_try.txt
for /f "tokens=1,2,3*" %%i in (try.txt) do set var1=%%i && if "CCC " == "!var1!" (echo CCC = 55.33>>n_try.txt) else (echo %%i %%j %%k>>n_try.txt)
pause
Floor 6 Posted 2006-01-13 14:00 ·  中国 河北 唐山 联通
版主
★★★
操作系统爱好者
Credits 1,113
Posts 392
Joined 2002-11-11 00:00
23-year member
UID 228
Gender Male
Status Offline
I use HEXC, which is only 5KB, smaller than XCHANGE, but the function is a bit simpler, it's enough.
hexc Try.txt Try.txt "CCC = 13.4" "CCC = 55.33" /u
Attachments
HEXC.rar (4.21 KiB, Credits to download 1 pts, Downloads: 57)
DOS之家 http://doshome.com 站长 葛明阳
Floor 7 Posted 2006-01-14 22:17 ·  中国 湖北 武汉 电信
初级用户
Credits 97
Posts 32
Joined 2005-12-03 19:43
20-year member
UID 46432
Gender Male
Status Offline
It is best not to use third - party tools, otherwise the value of batch processing cannot be realized
Floor 8 Posted 2006-01-15 20:06 ·  中国 山西 运城 中移铁通
元老会员
★★★★
Batchinger
Credits 4,432
Posts 1,512
Joined 2002-10-18 00:00
23-year member
UID 19
Gender Male
Status Offline
Re vptdosme:

Brother arding provided a program on the 5th floor. That is, if there is no third-party program used in CMD, if you want to implement it under Win9x/DOS, it will be much more complicated. You need to use a text traversal algorithm or use an ASCII assembler to echo out a similar replacement program for replacement. Unless it is really necessary, it is generally not recommended to adopt it.
※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!
Floor 9 Posted 2006-02-16 09:57 ·  中国 台湾 中华电信(HiNet)数据中心
初级用户
★★
Credits 154
Posts 54
Joined 2005-09-25 01:53
20-year member
UID 42804
Status Offline
Originally posted by Wengier at 2005-12-11 11:29:
Is third-party tool usage allowed? If allowed, you can try tools like XCHANGE, which can be solved in one line. For example, try this command (XCHANGE is in the attachment):

XCHANGE Try.txt "CCC ...

Sorry, this method doesn't seem to work
Because CCC =12.5 #TEST
If it is CCC =12.5 #TEST
The number of spaces after each person's modification is not fixed, so that's why my title says
Modify specific line data
And the version owner proposed a string, so can you help solve it?
Thanks
Floor 10 Posted 2006-02-16 10:09 ·  中国 台湾 中华电信(HiNet)数据中心
初级用户
★★
Credits 154
Posts 54
Joined 2005-09-25 01:53
20-year member
UID 42804
Status Offline
Originally posted by arding at 2006-1-12 20:18:
@echo off & setlocal EnableDelayedExpansion
echo.>n_try.txt
for /f "tokens=1,2,3*" %%i in (try.txt) do set var1=%%i && if "CCC " == "!var1!" (ec ...

This method can indeed modify, but there is a problem. It will cut off the data. That is, when your space is generated by the TAB key, the subsequent data is all cut off. Is there a way to overcome this? Thanks.
Modify the line 11b_ATTEN_DUT_PM

Original data

11b_ATTEN_DUT_SA = 15.5; # Attenuation at 2.5GHz between DUT and spectrum analyzer (double)
11b_ATTEN_FIXED_DUT_GOLDEN = 41.8; # Fixed attenuation at 2.5GHz between DUT and GOLDEN (double)
11b_ATTEN_DUT_PM = 21.4; # Attenuation at 2.5GHz between DUT and power meter (double)


Data after execution

11b_ATTEN_DUT_SA = 15.5;
11b_ATTEN_FIXED_DUT_GOLDEN = 41.8;
11b_ATTEN_DUT_PM = 33.55;
Floor 11 Posted 2006-02-16 11:45 ·  中国 山西 大同 中移铁通
元老会员
★★★★
Batchinger
Credits 4,432
Posts 1,512
Joined 2002-10-18 00:00
23-year member
UID 19
Gender Male
Status Offline
Re dosfroum:

This has nothing to do with tab. When /f is used without parameters, it recognizes tab as a delimiter. The main reason is that the output of %%l is omitted in the original program. The example is as follows:


@echo off
if exist tabo.txt del tabo.txt
for /f "tokens=1,2,3*" %%i in (tab.txt) do (
if "%%i"=="11b_ATTEN_DUT_PM" (echo %%i %%j 33.55 %%l>>tabo.txt) else (echo %%i %%j %%k %%l>>tabo.txt)
)
※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!
Floor 12 Posted 2006-02-16 22:52 ·  中国 广东 云浮 电信
荣誉版主
★★★
Credits 718
Posts 313
Joined 2005-09-26 00:00
20-year member
UID 42844
Gender Male
Status Offline
Re willsort:

There is a small mistake in your program, the semicolon is lost. Also, the program did not generate the "execution data" that dosfroum expects; instead, it followed the subsequent comments.
Floor 13 Posted 2006-02-17 09:02 ·  中国 山西 大同 中移铁通
元老会员
★★★★
Batchinger
Credits 4,432
Posts 1,512
Joined 2002-10-18 00:00
23-year member
UID 19
Gender Male
Status Offline
Re 220110:

The semicolon was indeed my oversight; due to time constraints, I didn't conduct strict testing. As for the comments, my understanding is that Brother dosfroum hoped to retain those comment information. As for these information losing the original alignment effect, that is the limitation of for /f. We can consider changing the spaces between %%i %%j %%k %%l to tabs, but the effect still may not be very ideal. If using awk, we can use a function similar to C language printf to achieve text alignment.
※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!
Floor 14 Posted 2006-02-17 15:25 ·  中国 台湾 中华电信(HiNet)数据中心
初级用户
★★
Credits 154
Posts 54
Joined 2005-09-25 01:53
20-year member
UID 42804
Status Offline
Could you change it so that the data except for that line can remain unchanged? A lot of blanks were removed, but it's already much better than before. Thanks!!

Before execution

11b_ATTEN_DUT_SA = 15.5; # Attenuation at 2.5GHz between DUT and spectrum analyzer (double)
11b_ATTEN_FIXED_DUT_GOLDEN = 41.8; # Fixed attenuation at 2.5GHz between DUT and GOLDEN (double)
11b_ATTEN_DUT_PM = 21.4; # Attenuation at 2.5GHz between DUT and power meter (double)

2442 0 -85 0 -90 1 1111 0 0 6.0
# 2447 1 -85 0 -90 0 1111 0 1 6.0
# 2452 1 -85 0 -90 0 1111 0 1 6.0
# 2457 1 -85 0 -90 0 1111 0 1 6.0
# 2462 1 -85 0 -90 0 1111 0 1 6.0
# 2467 1 -85 0 -90 0 1111 0 1 6.0
# 2472 1 -85 0 -90 0 1111 0 1 6.0
2484 1 -85 0 -90 0 1111 0 1 6.0


After execution

11b_ATTEN_DUT_SA = 15.5; # Attenuation at 2.5GHz between DUT and spectrum analyzer (double)
11b_ATTEN_FIXED_DUT_GOLDEN = 41.8; # Fixed attenuation at 2.5GHz between DUT and GOLDEN (double)
11b_ATTEN_DUT_PM = 33.55 # Attenuation at 2.5GHz between DUT and power meter (double)

2442 0 -85 0 -90 1 1111 0 0 6.0
# 2447 1 -85 0 -90 0 1111 0 1 6.0
# 2452 1 -85 0 -90 0 1111 0 1 6.0
# 2457 1 -85 0 -90 0 1111 0 1 6.0
# 2462 1 -85 0 -90 0 1111 0 1 6.0
# 2467 1 -85 0 -90 0 1111 0 1 6.0
# 2472 1 -85 0 -90 0 1111 0 1 6.0
Floor 15 Posted 2006-02-17 15:44 ·  中国 台湾 中华电信(HiNet)数据中心
初级用户
★★
Credits 154
Posts 54
Joined 2005-09-25 01:53
20-year member
UID 42804
Status Offline
Sorry
Found another problem
The blank in the first grid will increase
And the value is not modified

Batch file

@Echo on
C:
CD\
attrib -R -S -A -H boot.ini
copy boot.ini+boot.txt Boot.ini

if exist temp.txt del temp.txt
for /f "tokens=1,2,3*" %%i in (boot.ini) do (
if "%%i"=="timeout" (echo %%i %%j 3 %%l>>temp.txt) else (echo %%i %%j %%k %%l>>temp.txt)
)

attrib +S +A +H boot.ini

rem del addboot.bat


Original file


timeout=35
default=multi(0)disk(0)rdisk(0)partition(1)\WINNT

multi(0)disk(0)rdisk(0)partition(1)\WINNT="Microsoft Windows 2000 Professional" /fastdetect


After batch processing


timeout=35
default=multi(0)disk(0)rdisk(0)partition(1)\WINNT

multi(0)disk(0)rdisk(0)partition(1)\WINNT="Microsoft Windows 2000 Professional" /fastdetect
C:\ieldr="Boot From Virtual CD"


[ Last edited by dosfroum on 2006-2-17 at 15:45 ]
Forum Jump: