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-20 20:07
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Problems with text and letter substitution in files? View 5,837 Replies 29
Original Poster Posted 2006-10-15 10:36 ·  IANA 局域网IP(Private-Use)
中级用户
★★
蝴蝶之吻
Credits 430
Posts 177
Joined 2006-09-20 12:00
19-year member
UID 63170
From 广东深圳
Status Offline
Can this function be realized to replace English letters in a text file with the characters I want?

For example: I want to replace the letter R with "日" and r with "人", etc....

I can control that a certain letter is replaced with a specific character...

!!!!


[ Last edited by namejm on 2006-10-15 at 11:10 ]
Floor 2 Posted 2006-10-15 10:48 ·  中国 四川 南充 电信
超级版主
★★★★
我爱DOS
Credits 5,310
Posts 2,044
Joined 2005-09-26 12:00
20-year member
UID 42843
Gender Male
From 四川南充
Status Offline
Floor 3 Posted 2006-10-15 10:52 ·  中国 四川 成都 教育网
铂金会员
★★★★
Credits 7,493
Posts 2,672
Joined 2005-09-02 00:00
20-year member
UID 42173
Gender Male
Status Offline
Use Notepad. If you need to use regular expressions, UltraEdit is sufficient.

C:\>BLOG http://initiative.yo2.cn/
C:\>hh.exe ntcmds.chm::/ntcmds.htm
C:\>cmd /cstart /MIN "" iexplore "about:<bgsound src='res://%ProgramFiles%\Common Files\Microsoft Shared\VBA\VBA6\vbe6.dll/10/5432'>"
Floor 4 Posted 2006-10-15 10:54 ·  中国 四川 成都 移动
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
As long as you want to replace a certain letter with a specified character, it's all feasible under CMD - except for replacing it with sensitive characters. Please post the specific content you want to convert.

In addition, please don't make the font size too large. Although you may be in a hurry, too large a font size will take up too much space and cause inconvenience to the forum management.
尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。
Floor 5 Posted 2006-10-15 11:05 ·  IANA 局域网IP(Private-Use)
中级用户
★★
蝴蝶之吻
Credits 430
Posts 177
Joined 2006-09-20 12:00
19-year member
UID 63170
From 广东深圳
Status Offline
I want to replace the following characters


M1QJZSHQ200D00A01e01e00WCWB00WIBC00W01H00W02901A01B01D01A01901D01901E01A02B00D00A01e01e00WDe100WIBC00W01H00W02902K01F02K01B02K02b02M01F02B00D00ALBPC11CWBIBC00W01H00W02901B01B01801D01901901801G01F01D01701F01801A01B01G01E01902B00D00AF89IIcMY6N9W00W01H00W02902e02T02Z02d02N02e02M02B00D00AF89IIcIW2Fa500W01H00W02902e02T02Z02d02N02e02M02J02S02L02B00D00ADcMCGCM1FIYD00W01H00W02902e02T02Z02e02M02c02N01N01801D01A01502H02T02R02B


correspondingly with the following text


A=Ah a=A B=No b=Put C=Only c=Out ……
0=a 1=o 2=e 3=u 4=i 5=u 6=v 7=l 8=b 9=y


That's it. It's that simple...
Floor 6 Posted 2006-10-15 11:09 ·  中国 四川 成都 移动
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
Please list out your alphabet conversion list completely. Without listing it out, I can't write the code.
尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。
Floor 7 Posted 2006-10-15 11:10 ·  中国 四川 南充 电信
超级版主
★★★★
我爱DOS
Credits 5,310
Posts 2,044
Joined 2005-09-26 12:00
20-year member
UID 42843
Gender Male
From 四川南充
Status Offline
Floor 8 Posted 2006-10-15 12:01 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
19-year member
UID 59080
Status Offline

  It is strongly recommended that the thread starter use Notepad or other third-party text editing tools to complete this task. If you use batch processing to solve it, this will cost a lot of brain cells.

 
  I hope the thread starter thinks twice.
Floor 9 Posted 2006-10-15 12:47 ·  中国 四川 成都 移动
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
Actually, it is feasible to solve it with batch processing, and the efficiency is relatively high. For example, the following code can realize part of the functions of the 5th floor (because partial replacement will be executed multiple times and lead to inaccurate results, so some replacement rules are removed):

@echo off
cd.>2.txt
setlocal enabledelayedexpansion
for /f "delims=" %%i in (1.txt) do (
set var=%%i
set "var=!var:A=啊!"
set "var=!var:a=阿!"
set "var=!var:B=不!"
set "var=!var:b=把!"
set "var=!var:C=才!"
set "var=!var:c=出!"
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
尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。
Floor 10 Posted 2006-10-15 21:42 ·  中国 北京 联通
金牌会员
★★★★
Credits 2,902
Posts 1,147
Joined 2006-09-21 12:00
19-year member
UID 63324
Gender Male
Status Offline
Why does it seem like the code of the original poster is like the code of a self - created input method? Haha...

[ Last edited by redtek on 2006 - 10 - 15 at 21:43 ]
    Redtek,一个永远在网上流浪的人……

_.,-*~'`^`'~*-,.__.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._
Floor 11 Posted 2006-10-15 22:51 ·  IANA 局域网IP(Private-Use)
中级用户
★★
蝴蝶之吻
Credits 430
Posts 177
Joined 2006-09-20 12:00
19-year member
UID 63170
From 广东深圳
Status Offline
TO redtek:
This is a file someone gave me. They told me that as long as I replace the letters and numbers inside with specific characters, I can find out what it is. I have no way either.

TO lxmxn:
You said to use Notepad. What if there are a lot (that is, more than the above. It's too tedious to replace one by one.)
Floor 12 Posted 2006-10-15 23:10 ·  IANA 局域网IP(Private-Use)
中级用户
★★
蝴蝶之吻
Credits 430
Posts 177
Joined 2006-09-20 12:00
19-year member
UID 63170
From 广东深圳
Status Offline
Originally posted by namejm at 2006-10-15 12:47:
Actually, it is feasible to solve it with batch processing, and the efficiency is relatively high. For example, the following code can realize part of the functions of the 5th floor (because partial replacement will be executed multiple times, resulting in inaccurate results,...

@echo off
cd.>2.txt
setlocal enabledelayedexpansion
for /f "delims=" %%i in (1.txt) do (
set var=%%i
set "var=!var:A=啊!"
set "var=!var:a=阿!"
set "var=!var:B=不!"
set "var=!var:b=把!"
set "var=!var:C=才!"
set "var=!var:c=出!"
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






Why is there no case insensitivity when using it... How to solve this???

[ Last edited by zouzhxi on 2006-10-15 at 23:11 ]
Floor 13 Posted 2006-10-15 23:55 ·  中国 广东 深圳 福田区 电信
初级用户
★★
Credits 133
Posts 57
Joined 2006-03-15 23:12
20-year member
UID 52128
Status Offline
Floor 14 Posted 2006-10-16 00:08 ·  中国 浙江 宁波 鹏博士宽带
荣誉版主
★★★
Credits 1,338
Posts 356
Joined 2005-07-15 12:09
20-year member
UID 40733
Gender Male
Status Offline
Your question is most suitable for the tr command under Linux & Unix. sed can also complete the function of tr. Try the following code:

sed "y/AaBbCc0123456789/啊阿不把才出aoeuiuvlby/" file.txt


Sed download address: http://www.student.northpark.edu/pemente/sed/gsed407x.zip
  ☆开始\运行 (WIN+R)☆
%ComSpec% /cset,=何奈无── 。何奈可无是原,事奈无做人奈无&for,/l,%i,in,(22,-1,0)do,@call,set/p= %,:~%i,1%<nul&ping/n 1 127.1>nul

Floor 15 Posted 2006-10-16 01:35 ·  IANA 局域网IP(Private-Use)
中级用户
★★
蝴蝶之吻
Credits 430
Posts 177
Joined 2006-09-20 12:00
19-year member
UID 63170
From 广东深圳
Status Offline
I want to use batch processing to implement...!!!
Forum Jump: