|
dosfroum
初级用户
 
积分 154
发帖 54
注册 2005-9-25
状态 离线
|
『楼 主』:
請文如何將一的檔案中的某一行文字換成你需要的文字
使用 LLM 解释/回答一下
假如有一檔案 Try.txt內容如下
AAA = 10.7
BBB = 11.6
CCC = 13.4
DDD = 15.8
EEE = 17.1
如果要用批次檔的方次把
"CCC = 13.4"
這行至換成
"CCC = 55.33"
這樣子應該要如何寫
謝謝
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
|
|
2005-12-7 13:04 |
|
|
dosfroum
初级用户
 
积分 154
发帖 54
注册 2005-9-25
状态 离线
|
『第 2 楼』:
使用 LLM 解释/回答一下
這個問題應該會有不少人遇到
或者是需要
是太簡單了 還是 無解阿
都沒消沒息的@@
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 @@
|
|
2005-12-11 10:57 |
|
|
Wengier
系统支持
             “新DOS时代”站长
积分 27736
发帖 10521
注册 2002-10-9
状态 离线
|
『第 3 楼』:
使用 LLM 解释/回答一下
允許使用第三方工具麼?如果允許的話,可以試試XCHANGE之類的工具,一行就可以解決。例如試試這條命令(XCHANGE見附件):
XCHANGE Try.txt "CCC = 13.4" "CCC = 55.33"
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"
附件
1: XCHANGE.EXE (2005-12-11 11:31, 22.04 KiB, 下载附件所需积分 1 点
,下载次数: 94)
|

Wengier - 新DOS时代
欢迎大家来到我的“新DOS时代”网站,里面有各类DOS软件和资料,地址:
http://wendos.mycool.net/
E-Mail & MSN: wengierwu AT hotmail.com (最近比较忙,有事请联系DOSroot和雨露,谢谢!)
 |
|
2005-12-11 11:29 |
|
|
zreo
初级用户
 
积分 51
发帖 14
注册 2005-11-6
状态 离线
|
『第 4 楼』:
使用 LLM 解释/回答一下
有这个工具的应用祥解吗?
Is there a detailed application explanation of this tool?
|
|
2005-12-11 14:30 |
|
|
arding
初级用户
 
积分 90
发帖 38
注册 2006-1-6
状态 离线
|
『第 5 楼』:
使用 LLM 解释/回答一下
@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
```@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
|
|
2006-1-12 20:18 |
|
|
gmy
版主
        操作系统爱好者
积分 1113
发帖 392
注册 2002-11-11
状态 离线
|
『第 6 楼』:
使用 LLM 解释/回答一下
我用 HEXC,只有5KB,比XCHANGE更小巧,但功能简单了一些,够用了。
hexc Try.txt Try.txt "CCC = 13.4" "CCC = 55.33" /u
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
附件
1: HEXC.rar (2006-1-13 14:00, 4.21 KiB, 下载附件所需积分 1 点
,下载次数: 57)
|

DOS之家 http://doshome.com 站长 葛明阳 |
|
2006-1-13 14:00 |
|
|
vptdosme
初级用户
 
积分 97
发帖 32
注册 2005-12-3
状态 离线
|
『第 7 楼』:
使用 LLM 解释/回答一下
最好不要使用第三方工具,否则无法实现批处理的价值
It is best not to use third - party tools, otherwise the value of batch processing cannot be realized
|
|
2006-1-14 22:17 |
|
|
willsort
元老会员
         Batchinger
积分 4432
发帖 1512
注册 2002-10-18
状态 离线
|
『第 8 楼』:
使用 LLM 解释/回答一下
Re vptdosme:
arding 兄在5楼提供的程序,即是 CMD 下没有使用第三方程序,若想在 Win9x/DOS 下实现,则会复杂很多,需要使用文本遍历算法或者利用ASCII汇编器echo出一个类似的替换程序进行替换,除非确有必要,一般不建议采用。
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:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得! |
|
2006-1-15 20:06 |
|
|
dosfroum
初级用户
 
积分 154
发帖 54
注册 2005-9-25
状态 离线
|
『第 9 楼』:
使用 LLM 解释/回答一下
Originally posted by Wengier at 2005-12-11 11:29:
允許使用第三方工具麼?如果允許的話,可以試試XCHANGE之類的工具,一行就可以解決。例如試試這條命令(XCHANGE見附件):
XCHANGE Try.txt "CCC ...
對不起這個方好好像不行
因為 CCC =12.5 #TEST
要是 CCC =12.5 #TEST
每個人修改後的空格數不固定所以我的標題才會寫
修改特定一行資料
而版大提出來的是字串 所以可否幫忙解決一下
謝謝
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
|
|
2006-2-16 09:57 |
|
|
dosfroum
初级用户
 
积分 154
发帖 54
注册 2005-9-25
状态 离线
|
『第 10 楼』:
使用 LLM 解释/回答一下
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 ...
這個方式的確可以修改 但是有個問題 他會砍資料 就是當你的空格適用TAB鍵產生的 後段的資料全部砍掉 有辦法克服嗎 謝謝
修改 11b_ATTEN_DUT_PM 這行
原始資料
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)
執行後資料
11b_ATTEN_DUT_SA = 15.5;
11b_ATTEN_FIXED_DUT_GOLDEN = 41.8;
11b_ATTEN_DUT_PM = 33.55;
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;
|
|
2006-2-16 10:09 |
|
|
willsort
元老会员
         Batchinger
积分 4432
发帖 1512
注册 2002-10-18
状态 离线
|
『第 11 楼』:
使用 LLM 解释/回答一下
Re dosfroum:
这与 tab 没有什么关系,for /f 缺省时是承认 tab 作为切分符的。主要是因为原程序中遗漏了 %%l 的输出。例句如下:
@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)
)
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:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得! |
|
2006-2-16 11:45 |
|
|
220110
荣誉版主
      
积分 718
发帖 313
注册 2005-9-26
状态 离线
|
『第 12 楼』:
使用 LLM 解释/回答一下
Re willsort:
你的程序有小失误,把分号给丢失了。另,程序没有产生 dosfroum 希望的“执行后资料”;而把后边注释跟进了。
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.
|
|
2006-2-16 22:52 |
|
|
willsort
元老会员
         Batchinger
积分 4432
发帖 1512
注册 2002-10-18
状态 离线
|
『第 13 楼』:
使用 LLM 解释/回答一下
Re 220110:
分号确实是我的疏忽,时间所限,没有进行严格的测试。至于注释,我的理解是 dosfroum 兄是希望保留着些注释信息的,至于这些信息失去了原来的对齐效果,那就是 for /f 的局限所在了,可以考虑将%%i %%j %%k %%l 之间的空格改为Tab,但是效果仍然未必十分理想。如果使用 awk 的话,就可以使用类似C语言 printf 的函数来实现文本对齐了。
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:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得! |
|
2006-2-17 09:02 |
|
|
dosfroum
初级用户
 
积分 154
发帖 54
注册 2005-9-25
状态 离线
|
『第 14 楼』:
使用 LLM 解释/回答一下
請問可以改成 除了 那行以外的資料能不去變動嗎
好多空白被拿掉了 不過已經比之前的好很多了
感謝!!
執行前
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
執行後
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
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
|
|
2006-2-17 15:25 |
|
|
dosfroum
初级用户
 
积分 154
发帖 54
注册 2005-9-25
状态 离线
|
『第 15 楼』:
使用 LLM 解释/回答一下
對不起
發現另外一個問題
第一格的空白會增加
且值沒有修改到
批次檔
@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
原始檔
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
批處理後
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 ]
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 ]
|
|
2006-2-17 15:44 |
|