|
newice
初级用户
 
积分 70
发帖 24
注册 2005-9-20
状态 离线
|
『楼 主』:
如何去掉TXT文本首尾的符
使用 LLM 解释/回答一下
set IBV存放路径=D\disk\ibv
set 机器名前缀=XP-
set 客户机数量=200
if %客户机数量% leq 9 goto :9
if %客户机数量% leq 99 goto :99
if %客户机数量% leq 999 goto :999
goto :end
:9
for /l %%i in (1,1,9) do echo "<device name="IBV%%i" target="%机器名前缀%00%%i" file="My Computer\%IBV存放路径%\%机器名前缀%00%%i.ibv" mode="3" clustered="no" asyncmode="yes"/>" >>IBVcfg.txt
:99
for /l %%i in (1,1,9) do echo "<device name="IBV%%i" target="%机器名前缀%00%%i" file="My Computer\%IBV存放路径%\%机器名前缀%00%%i.ibv" mode="3" clustered="no" asyncmode="yes"/>" >>IBVcfg.txt
for /l %%i in (10,1,%客户机数量%) do echo "<device name="IBV%%i" target="%机器名前缀%0%%i" file="My Computer\%IBV存放路径%\%机器名前缀%0%%i.ibv" mode="3" clustered="no" asyncmode="yes"/>" >>IBVcfg.txt
:999
for /l %%i in (1,1,9) do echo "<device name="IBV%%i" target="%机器名前缀%00%%i" file="My Computer\%IBV存放路径%\%机器名前缀%00%%i.ibv" mode="3" clustered="no" asyncmode="yes"/>" >>IBVcfg.txt
for /l %%i in (10,1,99) do echo "<device name="IBV%%i" target="%机器名前缀%0%%i" file="My Computer\%IBV存放路径%\%机器名前缀%0%%i.ibv" mode="3" clustered="no" asyncmode="yes"/>" >>IBVcfg.txt
for /l %%i in (100,1,%客户机数量%) do echo "<device name="IBV%%i" target="%机器名前缀%%%i" file="My Computer\%IBV存放路径%\%机器名前缀%%%i.ibv" mode="3" clustered="no" asyncmode="yes"/>" >>IBVcfg.txt
:end
生存后是这样的
"<device name="IBV1" target="XP-001" file="My Computer\D\disk\ibv\XP-001.ibv" mode="3" clustered="no" asyncmode="yes"/>"
就是想去掉前面的“和后面的”
<device name="IBV1" target="XP-001" file="My Computer\D\disk\ibv\XP-001.ibv" mode="3" clustered="no" asyncmode="yes"/>
还有一个是取机器名的后面3个数字并定义为变量,有没更直观的方法
for /f %%i in ("%computername%") do (
set "name=%%i"
call set "name=%%name:~3,4%%")
set IBV storage path=D\disk\ibv
set machine name prefix=XP-
set number of clients=200
if %number of clients% leq 9 goto :9
if %number of clients% leq 99 goto :99
if %number of clients% leq 999 goto :999
goto :end
:9
for /l %%i in (1,1,9) do echo "<device name="IBV%%i" target="%machine name prefix%00%%i" file="My Computer\%IBV storage path%\%machine name prefix%00%%i.ibv" mode="3" clustered="no" asyncmode="yes"/>" >>IBVcfg.txt
:99
for /l %%i in (1,1,9) do echo "<device name="IBV%%i" target="%machine name prefix%00%%i" file="My Computer\%IBV storage path%\%machine name prefix%00%%i.ibv" mode="3" clustered="no" asyncmode="yes"/>" >>IBVcfg.txt
for /l %%i in (10,1,%number of clients%) do echo "<device name="IBV%%i" target="%machine name prefix%0%%i" file="My Computer\%IBV storage path%\%machine name prefix%0%%i.ibv" mode="3" clustered="no" asyncmode="yes"/>" >>IBVcfg.txt
:999
for /l %%i in (1,1,9) do echo "<device name="IBV%%i" target="%machine name prefix%00%%i" file="My Computer\%IBV storage path%\%machine name prefix%00%%i.ibv" mode="3" clustered="no" asyncmode="yes"/>" >>IBVcfg.txt
for /l %%i in (10,1,99) do echo "<device name="IBV%%i" target="%machine name prefix%0%%i" file="My Computer\%IBV storage path%\%machine name prefix%0%%i.ibv" mode="3" clustered="no" asyncmode="yes"/>" >>IBVcfg.txt
for /l %%i in (100,1,%number of clients%) do echo "<device name="IBV%%i" target="%machine name prefix%%%i" file="My Computer\%IBV storage path%\%machine name prefix%%%i.ibv" mode="3" clustered="no" asyncmode="yes"/>" >>IBVcfg.txt
:end
After generation, it is like this
"<device name="IBV1" target="XP-001" file="My Computer\D\disk\ibv\XP-001.ibv" mode="3" clustered="no" asyncmode="yes"/>"
Just want to remove the preceding "and the following"
<device name="IBV1" target="XP-001" file="My Computer\D\disk\ibv\XP-001.ibv" mode="3" clustered="no" asyncmode="yes"/>
There is also one that takes the last 3 digits of the machine name and defines it as a variable. Is there a more intuitive way
for /f %%i in ("%computername%") do (
set "name=%%i"
call set "name=%%name:~3,4%%")
|
|
2006-12-14 10:04 |
|
|
newice
初级用户
 
积分 70
发帖 24
注册 2005-9-20
状态 离线
|
|
2006-12-14 14:52 |
|
|
lxmxn
版主
       
积分 11386
发帖 4938
注册 2006-7-23
状态 离线
|
|
2006-12-14 15:30 |
|
|
newice
初级用户
 
积分 70
发帖 24
注册 2005-9-20
状态 离线
|
『第 4 楼』:
使用 LLM 解释/回答一下
后面的点没去掉,只去了前面的。
The dots at the back are not removed, only the ones at the front are removed.
|
|
2006-12-14 16:31 |
|
|
lxmxn
版主
       
积分 11386
发帖 4938
注册 2006-7-23
状态 离线
|
『第 5 楼』:
使用 LLM 解释/回答一下
我能得到正确的结果啊,我的IBVcfg.txt的内容是:
"<device name="IBV%%i" target="%机器名前缀%00%%i" file="My Computer\%IBV存放路径%\%机器名前缀%00%%i.ibv" mode="3" clustered="no" asyncmode="yes"/>"
"<device name="IBV%%i" target="%机器名前缀%0%%i" file="My Computer\%IBV存放路径%\%机器名前缀%0%%i.ibv" mode="3" clustered="no" asyncmode="yes"/>"
"<device name="IBV1" target="XP-001" file="My Computer\D\disk\ibv\XP-001.ibv" mode="3" clustered="no" asyncmode="yes"/>"
得到的结果是:
<device name="IBV%%i" target="%机器名前缀%00%%i" file="My Computer\%IBV存放路径%\%机器名前缀%00%%i.ibv" mode="3" clustered="no" asyncmode="yes"/>
<device name="IBV%%i" target="%机器名前缀%0%%i" file="My Computer\%IBV存放路径%\%机器名前缀%0%%i.ibv" mode="3" clustered="no" asyncmode="yes"/>
<device name="IBV1" target="XP-001" file="My Computer\D\disk\ibv\XP-001.ibv" mode="3" clustered="no" asyncmode="yes"/>
你再仔细检查一下。
I can get the correct result. The content of my IBVcfg.txt is:
"<device name="IBV%%i" target="%Machine name prefix%00%%i" file="My Computer\%IBV storage path%\%Machine name prefix%00%%i.ibv" mode="3" clustered="no" asyncmode="yes"/>"
"<device name="IBV%%i" target="%Machine name prefix%0%%i" file="My Computer\%IBV storage path%\%Machine name prefix%0%%i.ibv" mode="3" clustered="no" asyncmode="yes"/>"
"<device name="IBV1" target="XP-001" file="My Computer\D\disk\ibv\XP-001.ibv" mode="3" clustered="no" asyncmode="yes"/>"
The obtained result is:
<device name="IBV%%i" target="%Machine name prefix%00%%i" file="My Computer\%IBV storage path%\%Machine name prefix%00%%i.ibv" mode="3" clustered="no" asyncmode="yes"/>
<device name="IBV%%i" target="%Machine name prefix%0%%i" file="My Computer\%IBV storage path%\%Machine name prefix%0%%i.ibv" mode="3" clustered="no" asyncmode="yes"/>
<device name="IBV1" target="XP-001" file="My Computer\D\disk\ibv\XP-001.ibv" mode="3" clustered="no" asyncmode="yes"/>
Please check it carefully again.
|
|
2006-12-15 01:06 |
|
|
ccwan
金牌会员
     
积分 2725
发帖 1160
注册 2006-9-23 来自 河北廊坊
状态 离线
|
『第 6 楼』:
使用 LLM 解释/回答一下
的确。lxmxn兄的代码没有问题。加分!
Indeed. Brother lxmxn's code is correct. Add points!
|

三人行,必有吾师焉。 学然后知不足,教然后知困,然后能自强也。 |
|
2006-12-15 01:30 |
|
|
lh82102849
初级用户
 
积分 24
发帖 11
注册 2006-9-30
状态 离线
|
『第 7 楼』:
使用 LLM 解释/回答一下
学习了,感觉自己太差了
谢谢
Learned, feel that I am too bad
Thank you
|
|
2006-12-15 02:58 |
|
|
newice
初级用户
 
积分 70
发帖 24
注册 2005-9-20
状态 离线
|
『第 8 楼』:
使用 LLM 解释/回答一下
呵呵,还是这样的,麻烦再指点下哪里有错误
set IBV存放路径=D\disk\ibv
set 机器名前缀=XP-
set 客户机数量=200
if %客户机数量% leq 9 goto :9
if %客户机数量% leq 99 goto :99
if %客户机数量% leq 999 goto :999
goto :end
:9
for /l %%i in (1,1,9) do echo "<device name="IBV%%i" target="%机器名前缀%00%%i" file="My Computer\%IBV存放路径%\%机器名前缀%00%%i.ibv" mode="3" clustered="no" asyncmode="yes"/>" >>IBVcfg.txt
:99
for /l %%i in (1,1,9) do echo "<device name="IBV%%i" target="%机器名前缀%00%%i" file="My Computer\%IBV存放路径%\%机器名前缀%00%%i.ibv" mode="3" clustered="no" asyncmode="yes"/>" >>IBVcfg.txt
for /l %%i in (10,1,%客户机数量%) do echo "<device name="IBV%%i" target="%机器名前缀%0%%i" file="My Computer\%IBV存放路径%\%机器名前缀%0%%i.ibv" mode="3" clustered="no" asyncmode="yes"/>" >>IBVcfg.txt
:999
for /l %%i in (1,1,9) do echo "<device name="IBV%%i" target="%机器名前缀%00%%i" file="My Computer\%IBV存放路径%\%机器名前缀%00%%i.ibv" mode="3" clustered="no" asyncmode="yes"/>" >>IBVcfg.txt
for /l %%i in (10,1,99) do echo "<device name="IBV%%i" target="%机器名前缀%0%%i" file="My Computer\%IBV存放路径%\%机器名前缀%0%%i.ibv" mode="3" clustered="no" asyncmode="yes"/>" >>IBVcfg.txt
for /l %%i in (100,1,%客户机数量%) do echo "<device name="IBV%%i" target="%机器名前缀%%%i" file="My Computer\%IBV存放路径%\%机器名前缀%%%i.ibv" mode="3" clustered="no" asyncmode="yes"/>" >>IBVcfg.txt
:end
rem code by lxmxn @ cn-dos.net
@echo off
for /f "delims=" %%a in (IBVcfg.txt) do (
setlocal enabledelayedexpansion
set str=%%a
set str=!str:~1,-1!
echo !str! >>filename.txt
::echo 如果要输入到文件中,在echo !str!加上>>filename.txt
endlocal
)
pause
Hehe, it's still like this. Please give me some more pointers on where the errors are.
set IBV存放路径=D\disk\ibv
set 机器名前缀=XP-
set 客户机数量=200
if %客户机数量% leq 9 goto :9
if %客户机数量% leq 99 goto :99
if %客户机数量% leq 999 goto :999
goto :end
:9
for /l %%i in (1,1,9) do echo "<device name="IBV%%i" target="%机器名前缀%00%%i" file="My Computer\%IBV存放路径%\%机器名前缀%00%%i.ibv" mode="3" clustered="no" asyncmode="yes"/>" >>IBVcfg.txt
:99
for /l %%i in (1,1,9) do echo "<device name="IBV%%i" target="%机器名前缀%00%%i" file="My Computer\%IBV存放路径%\%机器名前缀%00%%i.ibv" mode="3" clustered="no" asyncmode="yes"/>" >>IBVcfg.txt
for /l %%i in (10,1,%客户机数量%) do echo "<device name="IBV%%i" target="%机器名前缀%0%%i" file="My Computer\%IBV存放路径%\%机器名前缀%0%%i.ibv" mode="3" clustered="no" asyncmode="yes"/>" >>IBVcfg.txt
:999
for /l %%i in (1,1,9) do echo "<device name="IBV%%i" target="%机器名前缀%00%%i" file="My Computer\%IBV存放路径%\%机器名前缀%00%%i.ibv" mode="3" clustered="no" asyncmode="yes"/>" >>IBVcfg.txt
for /l %%i in (10,1,99) do echo "<device name="IBV%%i" target="%机器名前缀%0%%i" file="My Computer\%IBV存放路径%\%机器名前缀%0%%i.ibv" mode="3" clustered="no" asyncmode="yes"/>" >>IBVcfg.txt
for /l %%i in (100,1,%客户机数量%) do echo "<device name="IBV%%i" target="%机器名前缀%%%i" file="My Computer\%IBV存放路径%\%机器名前缀%%%i.ibv" mode="3" clustered="no" asyncmode="yes"/>" >>IBVcfg.txt
:end
rem code by lxmxn @ cn-dos.net
@echo off
for /f "delims=" %%a in (IBVcfg.txt) do (
setlocal enabledelayedexpansion
set str=%%a
set str=!str:~1,-1!
echo !str! >>filename.txt
::echo 如果要输入到文件中,在echo !str!加上>>filename.txt
endlocal
)
pause
Hehe, it's still like this. Please give some more pointers on where the errors are.
set IBV storage path=D\disk\ibv
set machine name prefix=XP-
set number of clients=200
if %number of clients% leq 9 goto :9
if %number of clients% leq 99 goto :99
if %number of clients% leq 999 goto :999
goto :end
:9
for /l %%i in (1,1,9) do echo "<device name="IBV%%i" target="%machine name prefix%00%%i" file="My Computer\%IBV storage path%\%machine name prefix%00%%i.ibv" mode="3" clustered="no" asyncmode="yes"/>" >>IBVcfg.txt
:99
for /l %%i in (1,1,9) do echo "<device name="IBV%%i" target="%machine name prefix%00%%i" file="My Computer\%IBV storage path%\%machine name prefix%00%%i.ibv" mode="3" clustered="no" asyncmode="yes"/>" >>IBVcfg.txt
for /l %%i in (10,1,%number of clients%) do echo "<device name="IBV%%i" target="%machine name prefix%0%%i" file="My Computer\%IBV storage path%\%machine name prefix%0%%i.ibv" mode="3" clustered="no" asyncmode="yes"/>" >>IBVcfg.txt
:999
for /l %%i in (1,1,9) do echo "<device name="IBV%%i" target="%machine name prefix%00%%i" file="My Computer\%IBV storage path%\%machine name prefix%00%%i.ibv" mode="3" clustered="no" asyncmode="yes"/>" >>IBVcfg.txt
for /l %%i in (10,1,99) do echo "<device name="IBV%%i" target="%machine name prefix%0%%i" file="My Computer\%IBV storage path%\%machine name prefix%0%%i.ibv" mode="3" clustered="no" asyncmode="yes"/>" >>IBVcfg.txt
for /l %%i in (100,1,%number of clients%) do echo "<device name="IBV%%i" target="%machine name prefix%%%i" file="My Computer\%IBV storage path%\%machine name prefix%%%i.ibv" mode="3" clustered="no" asyncmode="yes"/>" >>IBVcfg.txt
:end
rem code by lxmxn @ cn-dos.net
@echo off
for /f "delims=" %%a in (IBVcfg.txt) do (
setlocal enabledelayedexpansion
set str=%%a
set str=!str:~1,-1!
echo !str! >>filename.txt
::echo If you want to input to the file, add >>filename.txt to echo !str!
endlocal
)
pause
|
|
2006-12-15 03:20 |
|
|
newice
初级用户
 
积分 70
发帖 24
注册 2005-9-20
状态 离线
|
『第 9 楼』:
使用 LLM 解释/回答一下
<device name="IBV1" target="XP-001" file="My Computer\D\disk\ibv\XP-001.ibv" mode="3" clustered="no" asyncmode="yes"/>"
生存后是这样的。后面还是有个点
<device name="IBV1" target="XP-001" file="My Computer\D\disk\ibv\XP-001.ibv" mode="3" clustered="no" asyncmode="yes"/>"
This is what it looks like after survival. There is still a dot at the end.
|
|
2006-12-15 03:21 |
|
|
lxmxn
版主
       
积分 11386
发帖 4938
注册 2006-7-23
状态 离线
|
『第 10 楼』:
使用 LLM 解释/回答一下
Re newice :
你我使用的代码并没有差别,而是由于你的IBVcfg.txt文件中的每一行后面有一个空格(仔细观察一下就可以发现了),导致批处理脚本没有达到你所要的要求。
解决方法是,再你的原代码里面,将输入重定向符号">>"前面的空格去掉,这样,生成的IBVcfg.txt文件的每一句之后就没有空格,也就可以用上面的代码来达到你的要求了。其实问题的本质,还是我的代码不健壮。
Re novice :
The code you and I are using is not different. It's because there is a space after each line in your IBVcfg.txt file (you can find it by carefully observing). This causes the batch script not to meet the requirements you want.
The solution is to remove the space in front of the input redirection symbol ">>" in your original code. In this way, there will be no space after each sentence in the generated IBVcfg.txt file, and then the above code can meet your requirements. In fact, the essence of the problem is still that my code is not robust.
|
|
2006-12-15 03:46 |
|
|
namejm
荣誉版主
       batch fan
积分 5226
发帖 1737
注册 2006-3-10 来自 成都
状态 离线
|
『第 11 楼』:
使用 LLM 解释/回答一下
用 for 语句的 %~i 扩展来去掉字符串首尾的引号更简洁一点:
@echo off
for /f "delims=" %%i in (IBVcfg.txt) do echo %%~i
pause
Using the %~i expansion in a for statement to remove the quotes at the beginning and end of a string is a bit more concise:
@echo off
for /f "delims=" %%i in (IBVcfg.txt) do echo %%~i
pause
此帖被 +3 点积分 点击查看详情 评分人:【 lxmxn 】 | 分数: +3 | 时间:2006-12-15 04:15 |
|
|

尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。 |
|
2006-12-15 03:53 |
|
|
newice
初级用户
 
积分 70
发帖 24
注册 2005-9-20
状态 离线
|
『第 12 楼』:
使用 LLM 解释/回答一下
谢谢斑竹和大大的帮忙,万分感谢!!!
Thanks to the moderator and the great person for the help, extremely grateful!!!
|
|
2006-12-15 04:04 |
|
|
lxmxn
版主
       
积分 11386
发帖 4938
注册 2006-7-23
状态 离线
|
『第 13 楼』:
使用 LLM 解释/回答一下
版主的代码好简洁,顶一个。
但是如果文本后面有一个空格,也不能很好的解决引号的问题。
The moderator's code is very concise, give a thumbs up.
But if there is a space after the text, it can't solve the problem of quotes well.
|
|
2006-12-15 04:15 |
|
|
vkill
金牌会员
     
积分 4103
发帖 1744
注册 2006-1-20 来自 甘肃.临泽
状态 离线
|
|
2006-12-16 10:00 |
|