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-24 03:23
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Discussion] Output the content of the specified line with special characters preserved to the greatest extent possible DigestI View 19,307 Replies 32
Floor 16 Posted 2007-05-18 14:13 ·  中国 广东 广州 电信
高级用户
★★★
潜水修练批处理
Credits 788
Posts 366
Joined 2006-12-31 02:43
19-year member
UID 75048
Gender Male
Status Offline
Is this okay?? Limited to output

type test.txt>output.txt
正在潜水修练的批处理小白
Floor 17 Posted 2007-05-18 14:18 ·  中国 浙江 杭州 华数宽带
银牌会员
★★★
Credits 2,000
Posts 621
Joined 2007-01-01 00:00
19-year member
UID 75212
Gender Male
Status Offline
?
Which post is the post above targeting?

I think when the number of quotation marks is odd, all the content after echo will be output;
Therefore, redirection is not possible;
I think the solution is to escape each quotation mark;

For even numbers, I think there will be no mistakes
Floor 18 Posted 2007-05-18 14:23 ·  中国 广东 电信
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
Hehe, the code I'm using is not your version, the statement is wrong, I take back this statement.
尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。
Floor 19 Posted 2007-05-18 14:27 ·  中国 广东 电信
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
Unknowingly, bjsh has solved all the output problems of special characters, and the remaining tasks are efficiency improvement and code simplification/standardization.
尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。
Floor 20 Posted 2007-05-18 14:29 ·  中国 广东 电信
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
Originally posted by dikex at 2007-5-18 14:13:
Is this okay?? Only for output

type test.txt>output.txt

  The type method is only limited to the output of the entire text, but what I want to discuss is the original output of all special characters in the content of the specified line. My title is a bit misleading, so I'll change it.
尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。
Floor 21 Posted 2007-05-18 14:44 ·  中国 浙江 杭州 华数宽带
银牌会员
★★★
Credits 2,000
Posts 621
Joined 2007-01-01 00:00
19-year member
UID 75212
Gender Male
Status Offline
Redirect to the code in the text

@echo off
if exist tmp.txt del tmp.txt
set var=
for /f "delims=" %%a in ('findstr /n .* test.txt') do (
set "var=%%a"
call set "var=%%var:"=%%"
call :change
)
goto :eof
:change
set "var=%var:^=^^%"
set "var=%var:>=^>%"
set "var=%var:<=^<%"
set "var=%var:&=^&%"
set "var=%var:|=^|%"
set "var=%var:*:=%"
if not defined var echo.>>tmp.txt & goto :eof
call set "var=%%var:="%%"
call echo.%%var%%>>tmp.txt

Notes:
In "call set "var=%%var:"=%%"", the " " in "%%" is not a space but a special character from ctrl+BackSpace;

[ Last edited by bjsh on 2007-5-18 at 02:47 PM ]
Floor 22 Posted 2007-05-22 21:00 ·  中国 青海 西宁 电信
金牌会员
★★★★
Credits 4,103
Posts 1,744
Joined 2006-01-20 13:00
20-year member
UID 49241
Gender Male
From 甘肃.临泽
Status Offline
I remember there was a very good solution in the post with the signature of Wuna iHe already!
Floor 23 Posted 2007-05-23 15:56 ·  中国 浙江 杭州 华数宽带
银牌会员
★★★
Credits 2,000
Posts 621
Joined 2007-01-01 00:00
19-year member
UID 75212
Gender Male
Status Offline
Latest code:
Concise and efficient

@echo off
for /f "delims=" %%a in ('findstr /n .* test.txt') do (
set "var=%%a"
setlocal enabledelayedexpansion
set var=!var:*:=!
echo.!var!
endlocal
)


Interested people help test
Recent Ratings for This Post ( 2 in total) Click for details
RaterScoreTime
vkill +6 2007-05-24 13:50
cutebe +1 2009-10-17 13:38
Floor 24 Posted 2007-05-23 22:41 ·  中国 广东 电信
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
This might be the most concise and efficient code. There's a lot to be done with variable delays.
尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。
Floor 25 Posted 2007-05-23 22:56 ·  中国 浙江 杭州 华数宽带
银牌会员
★★★
Credits 2,000
Posts 621
Joined 2007-01-01 00:00
19-year member
UID 75212
Gender Male
Status Offline
A brief analysis of the subtle relationship among environment variables, special characters for variable delay, and the intermediate method

This is the afterthought of writing the above code.

[ Last edited by bjsh on 2007-11-14 at 12:11 AM ]
Floor 26 Posted 2007-10-05 05:00 ·  中国 广东 广州 天河区 电信
初级用户
Credits 82
Posts 15
Joined 2007-05-26 20:14
19-year member
UID 89403
Gender Male
Status Offline
I don't know how the effect will be..
@echo off
for /f "eol= delims=" %%i in (a.txt) do (
set type=%%i
for /l %%j in (0,1,100) do (
setlocal EnableDelayedExpansion
if "!type:~%%j,1!"==" " (set/p= <nul)
if "!type:~%%j,1!"=="=" (set/p= <nul&set/p==<nul) else (
call set/p="%%type:~%%j,1%%"<nul)
endlocal)
echo.
)
pause>nul
Floor 27 Posted 2008-04-25 05:23 ·  中国 广东 深圳 罗湖区 电信
初级用户
Credits 27
Posts 11
Joined 2006-03-16 07:21
20-year member
UID 52148
Status Offline
Hehe `Not bad` `Admire` ``
Floor 28 Posted 2008-06-22 00:27 ·  中国 广东 清远 电信
高级用户
★★★
CMD感染者
Credits 691
Posts 383
Joined 2008-05-23 00:38
18-year member
UID 119451
Gender Male
Status Offline
Benefited a lot!
But there is still one problem: How to modify the text containing special symbols with P? For example:
Change test.txt
ip 125.219.59.216

sv_contact "568ggstart@163.Com"
// Contact email of the server builder

sv_send_resources 1
// Automatically send resource files included in the *.res file associated with the map to the client

sv_maxrate 25000
// Server maximum transmission rate <0-25000>


to:
ip 59.32.211.105

sv_contact "568ggstart@163.Com"
// Contact email of the server builder

sv_send_resources 1
// Automatically send resource files included in the *.res file associated with the map to the client

sv_maxrate 25000
// Server maximum transmission rate <0-25000>
Floor 29 Posted 2008-09-16 20:57 ·  中国 广东 广州 联通
初级用户
Credits 22
Posts 10
Joined 2008-09-15 03:00
17-year member
UID 125673
Gender Female
Status Offline
It's too profound. It's hard to say not to top it after just reading. But I'm afraid that topping it would make me look like an amateur joining in. Still, I'll top it.
Floor 30 Posted 2008-10-19 17:25 ·  中国 江西 赣州 电信
新手上路
Credits 13
Posts 15
Joined 2008-10-19 15:37
17-year member
UID 128763
Gender Male
Status Offline
Our several moderators are really very talented
Forum Jump: