|
123cainiao
初级用户
 
积分 97
发帖 41
注册 2007-8-30
状态 离线
|
『第 31 楼』:
仔细研究发现,还可以把问题作如下改动:
使用 LLM 解释/回答一下
ab.txt文件的内容如下:
[abcd]
doorCount = 1
goodpaIp = 127.0.0.1:8383
Max = 125
tackmoneys = 127.0.0.1:8086
doorCounttc = 12
doorCountwkl= 18
doorCountasd = 20
cd.txt文件内容如下:
[abcd]=
goodpaIp_name= goodip
tackmoneys_0=127.128.225.18
doorCounttc = 8
doorCountwkl= 185
doorCountasd = 20
现在可否从cd.txt文件里提取127.128.225.18来更新ab.txt文件
新生成的ab.txt文件为:
[abcd]
doorCount = 1
goodpaIp = 127.128.225.18:8383
Max = 125
tackmoneys = 127.128.225.18:8086
doorCounttc = 12
doorCountwkl= 18
doorCountasd = 20
请注意:127.128.225.18这个的位数先假设是变动的,也就是说即使他变成12.11.23.11或者其余位数的ip,都能实现完整替换。
.
Can we extract 127.128.225.18 from the cd.txt file to update the ab.txt file? The newly generated ab.txt file is:
doorCount = 1
goodpaIp = 127.128.225.18:8383
Max = 125
tackmoneys = 127.128.225.18:8086
doorCounttc = 12
doorCountwkl= 18
doorCountasd = 20
Please note: The number of digits of 127.128.225.18 is assumed to be variable, that is, even if it becomes an IP with other numbers of digits like 12.11.23.11 or others, the complete replacement can be achieved.
|
|
2007-9-25 19:15 |
|
|
terse
银牌会员
    
积分 2404
发帖 946
注册 2005-9-8
状态 离线
|
『第 32 楼』:
使用 LLM 解释/回答一下
@echo off
setlocal enabledelayedexpansion
ren ab.txt ab1.txt
for /f "tokens=1,2,3 delims==:" %%i in ('type cd.txt^|find /i "tackmoneys"') do set data=%%j
for /f "tokens=1,2,3 delims==: " %%i in ('type ab1.txt^|find /i "goodpaIp"') do set data1=%%j
for /f "tokens=1,2,3 delims==: " %%i in ('type ab1.txt^|find /i "tackmoneys"') do set data2=%%j
if !data! equ !data1! if !data! equ !data2! goto :eof
for /f "tokens=* delims==: " %%i in (ab1.txt) do (
set m=%%i
set m=!m:%data1%=%data%!
set m=!m:%data2%=%data%!
echo !m! >>ab2.txt
)
ren ab2.txt ab.txt
pause
@echo off
setlocal enabledelayedexpansion
ren ab.txt ab1.txt
for /f "tokens=1,2,3 delims==:" %%i in ('type cd.txt^|find /i "tackmoneys"') do set data=%%j
for /f "tokens=1,2,3 delims==: " %%i in ('type ab1.txt^|find /i "goodpaIp"') do set data1=%%j
for /f "tokens=1,2,3 delims==: " %%i in ('type ab1.txt^|find /i "tackmoneys"') do set data2=%%j
if !data! equ !data1! if !data! equ !data2! goto :eof
for /f "tokens=* delims==: " %%i in (ab1.txt) do (
set m=%%i
set m=!m:%data1%=%data%!
set m=!m:%data2%=%data%!
echo !m! >>ab2.txt
)
ren ab2.txt ab.txt
pause
|
|
2007-9-25 21:23 |
|
|
yoyodos
初级用户
 
积分 128
发帖 59
注册 2007-9-15
状态 离线
|
『第 33 楼』:
使用 LLM 解释/回答一下
我来贴个复杂的。。。
@echo off
cd.>new.txt
setlocal enabledelayedexpansion
set m=0
set a=0
set b=0
set cd_name=tackmoneys_0
set ab_name1=goodpaIp
set ab_name2=tackmoneys
for /f "delims=" %%i in (cd.txt) do (
call :cdcd %%i
)
for /f "delims=" %%y in (ab.txt) do (
call :abab %%y
)
for /f "delims=" %%y in (ab.txt) do (
set str=%%y
set str=!str:%ab_result1%=%cd_result%!
set str=!str:%ab_result2%=%cd_result%!
echo !str!>>new.txt
)
:abab
if "%1" == "" exit /b
if "%a%" == "1" (
set ab_result1=%1
for /f "tokens=1,2 delims=:" %%i in ("!ab_result1!") do set ab_result1=%%i
set a=0
exit /b
)
if "%b%" == "1" (
set ab_result2=%1
for /f "tokens=1,2 delims=:" %%i in ("!ab_result2!") do set ab_result2=%%i
set b=0
exit /b
)
if "%1" == "%ab_name1%" set a=1
if "%1" == "%ab_name2%" set b=1
shift
goto abab
:cdcd
if "%1" == "" exit /b
if "%m%" == "1" (
set cd_result=%1
set m=0
exit /b
)
if "%1" == "%cd_name%" set m=1
shift
goto cdcd
pause
123问题好多啊。,哈哈
Last edited by yoyodos on 2007-9-26 at 01:00 AM ]
I'll post a complicated one...
@echo off
cd.>new.txt
setlocal enabledelayedexpansion
set m=0
set a=0
set b=0
set cd_name=tackmoneys_0
set ab_name1=goodpaIp
set ab_name2=tackmoneys
for /f "delims=" %%i in (cd.txt) do (
call :cdcd %%i
)
for /f "delims=" %%y in (ab.txt) do (
call :abab %%y
)
for /f "delims=" %%y in (ab.txt) do (
set str=%%y
set str=!str:%ab_result1%=%cd_result%!
set str=!str:%ab_result2%=%cd_result%!
echo !str!>>new.txt
)
:abab
if "%1" == "" exit /b
if "%a%" == "1" (
set ab_result1=%1
for /f "tokens=1,2 delims=:" %%i in ("!ab_result1!") do set ab_result1=%%i
set a=0
exit /b
)
if "%b%" == "1" (
set ab_result2=%1
for /f "tokens=1,2 delims=:" %%i in ("!ab_result2!") do set ab_result2=%%i
set b=0
exit /b
)
if "%1" == "%ab_name1%" set a=1
if "%1" == "%ab_name2%" set b=1
shift
goto abab
:cdcd
if "%1" == "" exit /b
if "%m%" == "1" (
set cd_result=%1
set m=0
exit /b
)
if "%1" == "%cd_name%" set m=1
shift
goto cdcd
pause
So many problems with 123, haha
Last edited by yoyodos on 2007-9-26 at 01:00 AM ]
|
|
2007-9-26 00:58 |
|
|
123cainiao
初级用户
 
积分 97
发帖 41
注册 2007-8-30
状态 离线
|
『第 34 楼』:
使用 LLM 解释/回答一下
Originally posted by terse at 2007-9-25 09:23 PM:
@echo off
setlocal enabledelayedexpansion
ren ab.txt ab1.txt
for /f "tokens=1,2,3 delims==:" %%i in ('type cd.txt^|find /i "tackmoneys"') do set data=%%j
for /f "tokens ...
这段程序,反复测试,发现存在一个问题:
程序第一次运行,会生成一个ab1.txt和ab.txt里文件的参数一致,替换成功。
随便修改一下cd.txt里的值,再重新运行程序(不删除前次生成的ab1.txt)
发现提示文件重复,这时会生成ab2.txt,而且只有ab2.txt替换成功,ab.txt和ab1.txt均无变化。
再次修改一下cd.txt里的值,再重新运行程序(不删除前次生成的ab1.txt和ab2.txt)
结果程序提示文件重复,新的替换值以整体累加的形式出现在ab2.txt文件里,其余文件无替换。
Originally posted by terse at 2007-9-25 09:23 PM:
@echo off
setlocal enabledelayedexpansion
ren ab.txt ab1.txt
for /f "tokens=1,2,3 delims==:" %%i in ('type cd.txt^|find /i "tackmoneys"') do set data=%%j
for /f "tokens ...
This program, after repeated testing, is found to have a problem:
The first time the program runs, it will generate an ab1.txt which has the same parameters as the files in ab.txt, and the replacement is successful.
Modify the value in cd.txt casually, and then run the program again (without deleting the previously generated ab1.txt)
It is found that there is a file duplication prompt, and then ab2.txt will be generated, and only ab2.txt is successfully replaced, while ab.txt and ab1.txt remain unchanged.
Modify the value in cd.txt casually again, and then run the program again (without deleting the previously generated ab1.txt and ab2.txt)
As a result, the program prompts for file duplication, and the new replacement value appears in the ab2.txt file in a cumulative form, and no other files are replaced.
|
|
2007-9-26 10:54 |
|
|
123cainiao
初级用户
 
积分 97
发帖 41
注册 2007-8-30
状态 离线
|
『第 35 楼』:
使用 LLM 解释/回答一下
Originally posted by yoyodos at 2007-9-26 12:58 AM:
我来贴个复杂的。。。
@echo off
cd.>new.txt
setlocal enabledelayedexpansion
set m=0
set a=0
set b=0
set cd_name=tackmoneys_0
set ab_name1=goodpaIp
set ab_name2=tackmone ...
这段程序虽然复杂的多,但经过反复测试,均表现正常!
Originally posted by yoyodos at 2007-9-26 12:58 AM:
I'll post a complicated one...
@echo off
cd.>new.txt
setlocal enabledelayedexpansion
set m=0
set a=0
set b=0
set cd_name=tackmoneys_0
set ab_name1=goodpaIp
set ab_name2=tackmone ...
Although this program is much more complicated, after repeated testing, it all performs normally!
|
|
2007-9-26 10:56 |
|
|
yoyodos
初级用户
 
积分 128
发帖 59
注册 2007-9-15
状态 离线
|
『第 36 楼』:
使用 LLM 解释/回答一下
terse写的没错拉,ab1.txt ab2.txt都是临时文件,每次删除了就ok了。呵呵
What Terse wrote is correct. Both ab1.txt and ab2.txt are temporary files. Just delete them each time and it's fine. Hehe
|
|
2007-9-26 11:04 |
|
|
yoyodos
初级用户
 
积分 128
发帖 59
注册 2007-9-15
状态 离线
|
『第 37 楼』:
使用 LLM 解释/回答一下
terse是通过特殊字符找ip的,我那个是通过指定的字符串的位置找ip的,思路不同罢了。
^_^
terse is to find the ip through special characters, and mine is to find the ip through the position of the specified string, just different ideas. ^_^
|
|
2007-9-26 11:10 |
|
|
terse
银牌会员
    
积分 2404
发帖 946
注册 2005-9-8
状态 离线
|
『第 38 楼』:
使用 LLM 解释/回答一下
Originally posted by 123cainiao at 2007-9-26 10:54:
这段程序,反复测试,发现存在一个问题:
程序第一次运行,会生成一个ab1.txt和ab.txt里文件的参数一致,替换成功。
随便修改一下cd.txt里的值,再 ...
ab1.txt 只是原ab.txt的备份而已 可以去掉这一步
或者这样试一下
@echo off
setlocal enabledelayedexpansion
cd.>ab2.txt
for /f "tokens=1,2,3 delims==:" %%i in ('type cd.txt^|find /i "tackmoneys"') do set data=%%j
for /f "tokens=1,2,3 delims==: " %%i in ('type ab.txt^|find /i "goodpaIp"') do set data1=%%j
for /f "tokens=1,2,3 delims==: " %%i in ('type ab.txt^|find /i "tackmoneys"') do set data2=%%j
if !data! equ !data1! if !data! equ !data2! goto :eof
for /f "tokens=* delims==: " %%i in (ab.txt) do (
set m=%%i
set m=!m:%data1%=%data%!
set m=!m:%data2%=%data%!
echo !m! >>ab2.txt
)
del ab.txt
ren ab2.txt ab.txt
pause
Originally posted by 123cainiao at 2007-9-26 10:54:
There is a problem with this program after repeated testing:
When the program runs for the first time, it will generate a ab1.txt and the parameters in ab.txt are consistent, and the replacement is successful.
Modify the value in cd.txt casually, and then ...
ab1.txt is just a backup of the original ab.txt, this step can be removed
Or try it this way
@echo off
setlocal enabledelayedexpansion
cd.>ab2.txt
for /f "tokens=1,2,3 delims==:" %%i in ('type cd.txt^|find /i "tackmoneys"') do set data=%%j
for /f "tokens=1,2,3 delims==: " %%i in ('type ab.txt^|find /i "goodpaIp"') do set data1=%%j
for /f "tokens=1,2,3 delims==: " %%i in ('type ab.txt^|find /i "tackmoneys"') do set data2=%%j
if !data! equ !data1! if !data! equ !data2! goto :eof
for /f "tokens=* delims==: " %%i in (ab.txt) do (
set m=%%i
set m=!m:%data1%=%data%!
set m=!m:%data2%=%data%!
echo !m! >>ab2.txt
)
del ab.txt
ren ab2.txt ab.txt
pause
|
|
2007-9-26 11:27 |
|
|
123cainiao
初级用户
 
积分 97
发帖 41
注册 2007-8-30
状态 离线
|
『第 39 楼』:
使用 LLM 解释/回答一下
Originally posted by terse at 2007-9-26 11:27 AM:
ab1.txt 只是原ab.txt的备份而已 可以去掉这一步
或者这样试一下
@echo off
setlocal enabledelayedexpansion
cd.>ab2.txt
for /f "tokens=1,2,3 delims==:" %%i in ( ...
测试完毕,程序完全正常!
谢谢回复!
以上所有参考答案,仔细研究,融会贯通,完全可以解决类似文本字符串替换的其他问题。再次感谢所有回帖网友!
Originally posted by terse at 2007-9-26 11:27 AM:
ab1.txt is just a backup of the original ab.txt, this step can be removed
Or try it this way
@echo off
setlocal enabledelayedexpansion
cd.>ab2.txt
for /f "tokens=1,2,3 delims==:" %%i in ( ...
The test is complete, the program is completely normal!
Thank you for the reply!
All the above reference answers, after careful study and integration, can completely solve other problems of similar text string replacement. Thank you again to all the netizens who posted!
|
|
2007-9-26 13:06 |
|
|
yoyodos
初级用户
 
积分 128
发帖 59
注册 2007-9-15
状态 离线
|
『第 40 楼』:
使用 LLM 解释/回答一下
123继续出题呀.哈哈
123 continue to set questions. Haha
|
|
2007-9-26 15:03 |
|
|
yyf0346
初级用户
 
积分 128
发帖 56
注册 2007-9-26 来自 江苏 无锡
状态 离线
|
『第 41 楼』:
使用 LLM 解释/回答一下
我是菜鸟,刚来,我想请教一下各位,如何根据用户在窗口中输入的值来把指定文件中的某一字符串给替换掉。
比如有一个a.sql文件,和b.bat文件在同一个目录内,a.sql文件内有段内容:
EXECUTE @ReturnCode = msdb.dbo.sp_add_job @job_id = @JobID OUTPUT , @job_name = N'预定检查', @owner_login_name = N'localhost\Administrator', @description = N'没有可用的描述。', @category_name = N'[Uncategorized (Local)]', @enabled = 1, @notify_level_email = 0, @notify_level_page = 0, @notify_level_netsend = 0, @notify_level_eventlog = 2, @delete_level= 0
. . . . . . .
如何写b.bat文件,把其中的localhost换成用户输入的一个字符串;
又比如有一个INI文件夹里有一个a.INI文件,内容如下:
[CONNECT_DB]
CONNECTSTRING="Provider=SQLOLEDB.1;Password=MTIzNDU2;Persist Security Info=True;User ID=SA;Initial Catalog=HXGL_DB;Data Source=localhost\SQLEXPRESS1"
LatestLogin=admin
. . . . . .
此INI文件夹和b.bat不在一个目录结构内,要把localhost\SQLEXPRESS1换成用户输入的字符该怎么办?
我知道和用户交互是 SET /P char=请输入字符串:
那么怎么把这个用户输入的字符串按照上边的想法操作呢?我是在公司应用的,有谁能帮帮我啊?在此先谢谢大家了!
I'm a newbie, just came here. I want to ask you all, how to replace a certain string in a specified file according to the value entered by the user in the window.
For example, there is an a.sql file, and the b.bat file is in the same directory. There is a part of the content in the a.sql file:
EXECUTE @ReturnCode = msdb.dbo.sp_add_job @job_id = @JobID OUTPUT , @job_name = N'预定检查', @owner_login_name = N'localhost\Administrator', @description = N'没有可用的描述。', @category_name = N'', @enabled = 1, @notify_level_email = 0, @notify_level_page = 0, @notify_level_netsend = 0, @notify_level_eventlog = 2, @delete_level= 0
. . . . . . .
How to write the b.bat file to replace localhost with a string entered by the user;
For another example, there is an a.INI file in the INI folder, and the content is as follows:
CONNECTSTRING="Provider=SQLOLEDB.1;Password=MTIzNDU2;Persist Security Info=True;User ID=SA;Initial Catalog=HXGL_DB;Data Source=localhost\SQLEXPRESS1"
LatestLogin=admin
. . . . . .
This INI folder is not in the same directory structure as the b.bat. How to replace localhost\SQLEXPRESS1 with the entered character?
I know that interacting with the user is SET /P char=Please enter the string:
Then how to operate according to the above idea with the string entered by the user? I'm applying in the company. Can anyone help me? Thank you all in advance!
|
|
2007-9-26 16:32 |
|
|
yyf0346
初级用户
 
积分 128
发帖 56
注册 2007-9-26 来自 江苏 无锡
状态 离线
|
『第 42 楼』:
使用 LLM 解释/回答一下
没人回答我啊?555555
我是菜鸟,大家都照顾点............
等待中。。。。。。。。。
|
|
2007-9-26 16:41 |
|
|
wudixin96
银牌会员
    
积分 1928
发帖 931
注册 2007-1-6
状态 离线
|
『第 43 楼』:
使用 LLM 解释/回答一下
不是不回答,这种问题,请先搜索论坛,实在没有再提问吧
It's not that I don't answer. For such questions, please search the forum first. Only ask if there's really no answer after searching.
|
|
2007-9-26 16:54 |
|
|
terse
银牌会员
    
积分 2404
发帖 946
注册 2005-9-8
状态 离线
|
『第 44 楼』:
使用 LLM 解释/回答一下
@echo off
setlocal ENABLEDELAYEDEXPANSION
set str1=localhost\SQLEXPRESS1
SET /P STR2=输入替换字符
for /f "delims=" %%i in (路径\a.ini) do (
set str=%%i
set str=!str:%str1%=%str2%!
echo !str!>>路径\b.ini
)
pause
@echo off
setlocal ENABLEDELAYEDEXPANSION
set str1=localhost\SQLEXPRESS1
SET /P STR2=Enter replacement character
for /f "delims=" %%i in (Path\a.ini) do (
set str=%%i
set str=!str:%str1%=%str2%!
echo !str!>>Path\b.ini
)
pause
|
|
2007-9-26 16:56 |
|
|
yyf0346
初级用户
 
积分 128
发帖 56
注册 2007-9-26 来自 江苏 无锡
状态 离线
|
『第 45 楼』:
使用 LLM 解释/回答一下
:D
谢谢多谢以及不甚感谢!,由于刚来,有很多地方都不是很明白,可能我问的问题论坛里都有了,以后我会先查找论坛资源再发问的了,还请多多关照了....
:D
Thanks a lot and many thanks! Since I just joined, there are many things I don't understand. Maybe the questions I ask are already in the forum. In the future, I will search the forum resources first before asking questions. Please take care of me...
|
|
2007-9-26 18:03 |
|