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 13:53
中国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,393 Replies 16
Floor 16 Posted 2006-02-17 15:50 ·  中国 台湾 中华电信(HiNet)数据中心
初级用户
★★
Credits 154
Posts 54
Joined 2005-09-25 01:53
20-year member
UID 42804
Status Offline
The reason for the increase in blanks was this line:

if "%%i"=="timeout" (echo %%i %%j 3 %%l>>temp.txt) else (echo %%i %%j %%k %%l>>temp.txt)

There are two more blanks between %%i %%j. I don't know the reason for this. I directly shortened it to one space, and the problem of increased blanks was solved. There is still the problem of blanks being deleted, and the value has not been modified. I don't know where to start. Thanks.

[ Last edited by dosfroum on 2006-2-17 at 15:51 ]
Floor 17 Posted 2006-02-17 17:46 ·  中国 山西 大同 中移铁通
元老会员
★★★★
Batchinger
Credits 4,432
Posts 1,512
Joined 2002-10-18 00:00
23-year member
UID 19
Gender Male
Status Offline
Re dosfroum:

Whether it's increasing or decreasing spaces, this all belongs to the problem of text alignment, and it's related to the string splitting characteristics of for /f. It's not very simple to solve. If the current result can be applied, it's suggested not to use more complex code.

If it's really necessary, you can consider not using spaces or tabs as string splitting delimiters. You can consider using = or not using a delimiter. In this case, you need to use set to assist in "splicing" the string.

Or still use spaces as the splitting delimiter, but check the length of each string item, use set /a to calculate the number of spaces that should be filled, and then use for+set to fill the spaces.

There's not much time today. If you really need it and no other experts provide a solution, you can consider researching it deeply.
※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!
Forum Jump: