|
namejm
荣誉版主
       batch fan
积分 5226
发帖 1737
注册 2006-3-10 来自 成都
状态 离线
|
『第 16 楼』:
使用 LLM 解释/回答一下
看来set命令无法区分大小写,纯批处理恐怕难以实现,楼主还是去试试无奈何兄提供的sed命令吧,没必要强求用纯批处理来解决吧?
It seems that the set command cannot distinguish between case sensitivity, and it's恐怕 difficult to achieve with pure batch processing. The thread starter might as well try the sed command provided by Brother Wunaike. There's no need to insist on solving it with pure batch processing, right?
|

尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。 |
|
2006-10-16 10:37 |
|
|
pengfei
银牌会员
    
积分 1218
发帖 485
注册 2006-7-21 来自 湖南.娄底
状态 离线
|
『第 17 楼』:
使用 LLM 解释/回答一下
在9楼namejm版主代码的基础上修改了一下, 可以区别大小写.
@echo off
cd.>2.txt
setlocal enabledelayedexpansion
for /f "delims=" %%i in (test.txt) do (
set var=%%i
call :go
set "var=!var:1=o!"
set "var=!var:2=e!"
set "var=!var:3=u!"
set "var=!var:4=i!"
set "var=!var:5=u!"
set "var=!var:6=v!"
set "var=!var:7=l!"
set "var=!var:9=y!"
>>2.txt echo !var!
)
start 2.txt
exit
:go
set tmp=%var%@
set var=
:go_
if not "%tmp:~0,1%"=="@" (
set var_=%tmp:~0,1%
if "!var_!"=="A" set var_=啊
if "!var_!"=="a" set var_=阿
if "!var_!"=="B" set var_=不
if "!var_!"=="b" set var_=把
if "!var_!"=="C" set var_=才
if "!var_!"=="c" set var_=出
set var=!var!!var_!
set tmp=!tmp:~1!
goto go_
)
goto :eof
Last edited by pengfei on 2006-10-16 at 21:36 ]
Modified based on the code of moderator namejm on floor 9, which can distinguish case sensitivity.
@echo off
cd.>2.txt
setlocal enabledelayedexpansion
for /f "delims=" %%i in (test.txt) do (
set var=%%i
call :go
set "var=!var:1=o!"
set "var=!var:2=e!"
set "var=!var:3=u!"
set "var=!var:4=i!"
set "var=!var:5=u!"
set "var=!var:6=v!"
set "var=!var:7=l!"
set "var=!var:9=y!"
>>2.txt echo !var!
)
start 2.txt
exit
:go
set tmp=%var%@
set var=
:go_
if not "%tmp:~0,1%"=="@" (
set var_=%tmp:~0,1%
if "!var_!"=="A" set var_=啊
if "!var_!"=="a" set var_=阿
if "!var_!"=="B" set var_=不
if "!var_!"=="b" set var_=把
if "!var_!"=="C" set var_=才
if "!var_!"=="c" set var_=出
set var=!var!!var_!
set tmp=!tmp:~1!
goto go_
)
goto :eof
Last edited by pengfei on 2006-10-16 at 21:36 ]
|
|
2006-10-16 11:20 |
|
|
namejm
荣誉版主
       batch fan
积分 5226
发帖 1737
注册 2006-3-10 来自 成都
状态 离线
|
『第 18 楼』:
使用 LLM 解释/回答一下
pengfei 的代码是通过探测每一个字符来替换的,用了 if 可以区别大小写的特性,思路确实不错。
使用这段代码来处理小块文本内容还是可行的,如果文本内容很多的话,速度就会比较慢了。楼主可以综合考虑一下。
The code of pengfei is to replace by detecting each character, using the case-sensitive feature of if. The idea is really good.
It is still feasible to use this code to process small pieces of text content. If there is a lot of text content, the speed will be relatively slow. The poster can consider comprehensively.
|

尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。 |
|
2006-10-16 11:37 |
|
|
redtek
金牌会员
     
积分 2902
发帖 1147
注册 2006-9-21
状态 离线
|
『第 19 楼』:
使用 LLM 解释/回答一下
Originally posted by zouzhxi at 2006-10-15 22:51:
TO redtek:
这是别人给我的一个文件,,告诉我说,只要用特定字符替换掉里边的字母数字就可以知道是什么东东了.我也没办法,,,,
TO lxmxn:
你说用记事本 ...
别人给你的这个文件,用个工具替换一下就可以~:)
因为这只是一次性的,你的朋友或许给你这样类型的文件只有这一次,不会经常,
而且解码要求只有一小部分,就是做完了自动处理也只是个半成品,
(从心理因素讲:做半成品给朋友用自己也接受不了,没有挑战性和成就感,象是在打杂儿)
( 就像是走了一半将要到美丽公园的路,而中途不去就回家了一样,哈哈)
一次的文件还是用一些工具替换比较好~:)
但我猜这可能不是一次性的文件处理,
有可能是SQL存储上要用的私人性质编码和解码、
或是某个JavaScript上要用到的简单加密方式、
或是聊天要用到的明文简单加密编码,可能防止特殊字符或命令过滤或方便处理、
或是自定义上的象BASE64一样的编码和解码的应用、
或是某种日记等带有保密性的文档的自定义私有编码与解码等、
或是公司内部要求对某个文件内容进行的类似性的解码(如输入法、对照码表……)
所以,实际你上面的问题,如果每行数量不固定,如果有上万行,还含有特殊符号,等等……很多问题都会影响批处理的解决速度和解决办法。
例:几万行和几行的处理方法和算法也是不一样的:)
所以,如果你的内容不保密可以全上传上来让大家帮助你一起想办法。
请说明这件事的非常详细的应用(如果没有私人或企业秘密等条件所约束的话)~:)
) 一次的转换还是用工具好~:)
) 天天要用到的用批处理或调用工具的方便~:)
) 必须要用DOS而不是其它外部工具,这不太明白……(似乎要经常处理这些对吧?)
Originally posted by zouzhxi at 2006-10-15 22:51:
TO redtek:
This is a file someone gave me. They told me that I just need to replace the letters and numbers with specific characters to find out what it is. I have no way...
TO lxmxn:
You said use Notepad...
This file someone gave you, just use a tool to replace it~ : )
Because this is only a one-time thing. Your friend might only give you this type of file this once, not often.
And the decoding requires only a small part. Even if you do the automatic processing, it's just a half-finished product.
(From a psychological perspective: Making a half-finished product for a friend is unacceptable. It's not challenging or fulfilling, like doing menial work)
( It's like walking halfway to a beautiful park and then going home halfway, haha)
It's better to use some tools to replace the one-time file~ : )
But I guess this might not be a one-time file processing.
It might be SQL storage private encoding and decoding to use,
or a simple encryption method to use on some JavaScript,
or a simple plaintext encryption code to use for chatting, maybe to prevent special character or command filtering or for easy processing,
or a custom encoding and decoding application like BASE64,
or a custom private encoding and decoding for a confidential document like a diary,
or a similar decoding required by the company for a certain file content (such as input method, code table... )
So, actually, the above problem. If the number of lines per line is not fixed, if there are tens of thousands of lines, and special symbols are included, etc.... Many problems will affect the solution speed and method of batch processing.
Example: The processing methods and algorithms for tens of thousands of lines and a few lines are different~ : )
So, if your content is not confidential, you can upload it all to let everyone help you think of a way together.
Please explain the very detailed application of this matter (if there are no private or enterprise secrets or other constraints)~ : )
) One-time conversion is still better with tools~ : )
) For daily use, it's convenient to use batch processing or call tools~ : )
) Must use DOS instead of other external tools. This is not very clear... (It seems you need to process these often, right?)
|

Redtek,一个永远在网上流浪的人……
_.,-*~'`^`'~*-,.__.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._ |
|
2006-10-16 11:41 |
|
|
zouzhxi
中级用户
   蝴蝶之吻
积分 430
发帖 177
注册 2006-9-20 来自 广东深圳
状态 离线
|
『第 20 楼』:
使用 LLM 解释/回答一下
TO redtek:
是的,我朋友发给我的文件都是这样的,我不得不重复翻出来,所以我想写一个批处理,,,不想用其他工具(因为烦琐),批处理我一次执行就可以了....
TO redtek:
Yes, the files my friend sent me are all like this. I have to extract them repeatedly, so I want to write a batch script... I don't want to use other tools (because it's cumbersome). I can execute the batch script at once...
|

Butterfly Kiss Blog
计算机DIY联盟论坛 |
|
2006-10-17 01:20 |
|
|
zouzhxi
中级用户
   蝴蝶之吻
积分 430
发帖 177
注册 2006-9-20 来自 广东深圳
状态 离线
|
『第 21 楼』:
使用 LLM 解释/回答一下
『第 17 楼』:
在9楼namejm版主代码的基础上修改了一下, 可以区别大小写.
CODE:
--------------------------------------------------------------------------------
@echo off
cd.>2.txt
setlocal enabledelayedexpansion
for /f "delims=" %%i in (test.txt) do (
set var=%%i
call :go
set "var=!var:1=o!"
set "var=!var:2=e!"
set "var=!var:3=u!"
set "var=!var:4=i!"
set "var=!var:5=u!"
set "var=!var:6=v!"
set "var=!var:7=l!"
set "var=!var:9=y!"
>>2.txt echo !var!
)
start 2.txt
exit
:go
set tmp=%var%@
set var=
:go_
if not "%tmp:~0,1%"=="@" (
set var_=%tmp:~0,1%
if "!var_!"=="A" set var_=啊
if "!var_!"=="a" set var_=阿
if "!var_!"=="B" set var_=不
if "!var_!"=="b" set var_=把
if "!var_!"=="C" set var_=才
if "!var_!"=="c" set var_=出
set var=!var!!var_!
set tmp=!tmp:~1!
goto go_
)
goto :eof
我弄了好久,用上面的办法太慢了。不太理想。有没有精简一点的,。。
『Post 17』:
Modified based on the code of version master namejm on floor 9, which can distinguish case.
CODE:
--------------------------------------------------------------------------------
@echo off
cd.>2.txt
setlocal enabledelayedexpansion
for /f "delims=" %%i in (test.txt) do (
set var=%%i
call :go
set "var=!var:1=o!"
set "var=!var:2=e!"
set "var=!var:3=u!"
set "var=!var:4=i!"
set "var=!var:5=u!"
set "var=!var:6=v!"
set "var=!var:7=l!"
set "var=!var:9=y!"
>>2.txt echo !var!
)
start 2.txt
exit
:go
set tmp=%var%@
set var=
:go_
if not "%tmp:~0,1%"=="@" (
set var_=%tmp:~0,1%
if "!var_!"=="A" set var_=啊
if "!var_!"=="a" set var_=阿
if "!var_!"=="B" set var_=不
if "!var_!"=="b" set var_=把
if "!var_!"=="C" set var_=才
if "!var_!"=="c" set var_=出
set var=!var!!var_!
set tmp=!tmp:~1!
goto go_
)
goto :eof
I've been working on it for a long time, and the above method is too slow. Not ideal. Is there a more streamlined one, .
|

Butterfly Kiss Blog
计算机DIY联盟论坛 |
|
2006-10-21 04:16 |
|
|
redtek
金牌会员
     
积分 2902
发帖 1147
注册 2006-9-21
状态 离线
|
『第 22 楼』:
使用 LLM 解释/回答一下
还有一种方法(只是原理):
) 读全部变量到数组(可以模拟出数组功能来)
) 以数组内容为目的标签直接跳转
) 大写A与小写a同样指向标签A,在标签A内用IF判断大小写并替换
优点:二选一的方式只针对指定的字母,节省了每个字母都用IF判断的时间。
也就是说:只要替换内容分为大小写的,一次判断就够:
因为:如果 IF判断字母为大写(每个数组只装一个字符,省去了:~的提取运算),
那么就按大写的方式替换,否则一定是小写!所以一次判断解决。
如果是遇到其它符号,不管!反正是按数组内容跳标签的,到了属于它的标签内想怎么操作就怎么替换。
) 当数组全部走一遍之后,意味着内存中的数组内变量已全部更改替换完成
) 然后for循环再将数组内容从头到尾写回文件。
There is another method (just the principle):
) Read all variables into an array (can simulate array functionality)
) Jump directly with the array content as the target label
) Uppercase A and lowercase a both point to label A. Inside label A, use IF to judge the case and replace.
Advantage: The two-choice method is only for specified letters, saving the time of judging each letter with IF.
That is to say: As long as the replacement content is divided into case, one judgment is enough:
Because: If the IF judges that the letter is uppercase (each array only holds one character, eliminating the extraction operation of :~),
then it will be replaced in uppercase, otherwise it must be lowercase! So one judgment solves it.
If other symbols are encountered, it doesn't matter! Anyway, it jumps to the label belonging to it according to the array content, and you can replace as you like inside the label.
) After the entire array is processed, it means that the variables in the array in memory have been completely changed and replaced.
) Then use a for loop to write the array content back to the file from the beginning to the end.
|

Redtek,一个永远在网上流浪的人……
_.,-*~'`^`'~*-,.__.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._ |
|
2006-10-21 22:38 |
|
|
redtek
金牌会员
     
积分 2902
发帖 1147
注册 2006-9-21
状态 离线
|
『第 23 楼』:
使用 LLM 解释/回答一下
例如:
) 提取全部文本到数组,每个字符占一个数组元素。
) 以下面标签跳转:
CALL :数组元素1的内容
就上面这一行就足够了:)
在下面是标签:
:A
在标签A内来一个IF判断它是不是大写(是:替换什么字符),
如果它不是大写,那一定是小写,替换什么。
(所以这里一个判断就地了)
:1 在1的标签内,不要判断了,直接替换就行了。
优点: 通用,想替什么就替什么。
) 还有多少个要替换的内容往标签上加:)
) 最后当数组循环全走了一遍以后,一个FOR写文本内。
至于写进文本内的内容是不是一个元素就占一行的问题(要多少个元素占一行)
同样可以计算和 += 什么出来。
For example:
) Extract all text into an array, with each character occupying one array element.
) Jump with the following tag:
CALL :The content of array element 1
Just this line is enough:)
Below are the tags:
:A
In tag A, perform an IF judgment to see if it is uppercase (if yes: replace what character),
If it is not uppercase, it must be lowercase, replace what.
(So a judgment is done here)
:1 In tag 1, no need for judgment, just replace directly.
Advantage: Universal, replace whatever you want.
) How many more contents to replace are added to the tag:)
) Finally, after the array loop has gone through, write the text with a FOR.
As for the problem of whether the content written into the text is one element per line (how many elements per line)
The same can be calculated and += what comes out.
|

Redtek,一个永远在网上流浪的人……
_.,-*~'`^`'~*-,.__.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._ |
|
2006-10-21 22:46 |
|
|
95219320
新手上路

积分 2
发帖 1
注册 2006-11-12
状态 离线
|
『第 24 楼』:
使用 LLM 解释/回答一下
用记事本的替换功能好了。
Just use the replace function in Notepad.
|
|
2006-11-12 19:06 |
|
|
vkill
金牌会员
     
积分 4103
发帖 1744
注册 2006-1-20 来自 甘肃.临泽
状态 离线
|
『第 25 楼』:
使用 LLM 解释/回答一下
sed 解决这类问题最爽了
Using sed to solve such problems is really the best!
|
|
2006-11-13 01:29 |
|
|
zouzhxi
中级用户
   蝴蝶之吻
积分 430
发帖 177
注册 2006-9-20 来自 广东深圳
状态 离线
|
『第 26 楼』:
使用 LLM 解释/回答一下
这个问题差点忘了,,,
此问题未解决,,,
本人还在郁闷,,,
有没有更好的办法,,,
。。。。
This problem was almost forgotten...
This problem is not solved...
I'm still depressed...
Is there a better way...
......
|

Butterfly Kiss Blog
计算机DIY联盟论坛 |
|
2006-11-15 03:58 |
|
|
vkill
金牌会员
     
积分 4103
发帖 1744
注册 2006-1-20 来自 甘肃.临泽
状态 离线
|
『第 27 楼』:
使用 LLM 解释/回答一下
无奈何斑竹发的很详细了,怎么还没有解决?
Why hasn't it been solved yet even though the moderator posted very detailed information?
|
|
2006-11-16 03:58 |
|
|
vkill
金牌会员
     
积分 4103
发帖 1744
注册 2006-1-20 来自 甘肃.临泽
状态 离线
|
『第 28 楼』:
使用 LLM 解释/回答一下
不嫌麻烦可以这样写:
sed "s/A/啊/g;s/a/阿/g;......................" life (..........继续添加)
It can be written like this if you don't mind the trouble:
sed "s/A/啊/g;s/a/阿/g;......................" life (..........continue to add)
|
|
2006-11-16 04:00 |
|
|
hxuan999
中级用户
   DOS之日
积分 337
发帖 161
注册 2006-11-4
状态 离线
|
『第 29 楼』:
使用 LLM 解释/回答一下
没说的,顶一下
|

for /f %%h in (`echo hxuan`) do for /f %%x in (`echo hxuan`) do if %%h==%%x nul |
|
2006-11-23 06:30 |
|
|
myddos
新手上路

积分 4
发帖 2
注册 2007-8-31
状态 离线
|
『第 30 楼』:
使用 LLM 解释/回答一下
文本文档里不是有查找替换功能?
Isn't there a find and replace function in the text document?
|
|
2007-9-6 09:49 |
|