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-07-15 01:16
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Closed] Batch script to read text line by line, please help experts to improve DigestI View 14,329 Replies 31
Floor 16 Posted 2007-01-19 05:56 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
19-year member
UID 59080
Status Offline
Originally posted by chainliq at 2006-11-19 19:07:
Hehe, I actually find this quite interesting. May I ask how to fix its display speed?


  To modify its display speed, you can change the ping statement in the code. You can increase the value of the -n parameter or add the -w timeout parameter, depending on personal preference.
Floor 17 Posted 2007-01-19 06:14 ·  中国 北京 方正宽带
新手上路
Credits 14
Posts 7
Joined 2007-01-19 05:09
19-year member
UID 76975
Gender Male
Status Offline
Good stuff. Download and test it.
Floor 18 Posted 2007-02-03 00:03 ·  中国 广东 电信
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
lxmxn's post on floor 6 has a good code, but there are the following drawbacks:
1. Because the variable delay function is enabled, it will replace the exclamation marks in the text with empty;
2. Because the ordinary for statement ignores the lines starting with semicolons, this code will not be able to extract the content of these lines;
3. The :end in the if statement cannot be called as a label by other statements, that is, when the goto end part in other statements is executed, an error will occur and it cannot jump here;
4. The quotes in SET A="%1" are redundant, because when calling, %1 has been forcibly given quotes, so the sentence if "%A%"=="" goto end will never be executed;

Based on this code, the following code is obtained:

Version 1:

@echo off
:: Replace half-width double quotes with spaces, replace equal signs with 〓, compatible with other special characters
:: Can handle lines starting with semicolons, but will ignore blank lines
:: Can be compatible with unicode - formatted text
:: Display with a blank line between each line
for /f "delims= eol=" %%i in ('type %1') do (
set "str=%%i"
call set "str=%%str:"= %%"
call :pickup
)
pause
goto :eof

:pickup
ping -n 1 127.1>nul
if "%str:~0,1%"=="=" set "str=〓%str:~1%"
set /p "=%str:~0,1%"<nul
set "str=%str:~1%"
if defined str goto pickup
echo.&echo.
goto :eof


Version 2:

@echo off
:: Several differences from version 1:
::   1. Cannot handle unicode text
::   2. No longer forcibly add blank lines between each line, and can display blank lines as they are
for /f "delims= eol=" %%i in ('findstr /n .* %1') do (
set "str=%%i"
call set "str=%%str:"= %%"
call set "str=%%str:*:=%%"
call :pickup
)
echo.
pause
goto :eof

:pickup
if not defined str echo.&goto :eof
if "%str:~0,1%"=="=" set "str=〓%str:~1%"
set /p "=%str:~0,1%"<nul
ping -n 1 127.1>nul
set "str=%str:~1%"
if defined str goto pickup
echo.
goto :eof


[ Last edited by namejm on 2007 - 2 - 2 at 02:06 PM ]
尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。
Floor 19 Posted 2007-02-03 00:20 ·  中国 吉林 四平 联通
高级用户
★★★
Credits 859
Posts 413
Joined 2006-08-14 21:55
19-year member
UID 60532
Status Offline
It's really wonderful. Both lx and jm are all experts
Floor 20 Posted 2007-05-01 23:06 ·  中国 上海 徐汇区 电信
初级用户
Credits 94
Posts 40
Joined 2007-04-28 22:13
19-year member
UID 86806
Gender Male
Status Offline
Support
Floor 21 Posted 2007-05-30 11:30 ·  中国 广东 电信
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
According to the discussion results of the post Maximize the original output of the specified line content containing special characters, the following code is obtained, which can perfectly solve the problem of original display of special characters. It is sent out for everyone to test:


@echo off

:: Read the text line by line and display the text content as it is
:: ① In order to display all the content of the text, the for+findstr sentence pattern is used
:: ② In order to be able to display the text as it is, variable delay is used and the delay is terminated at the appropriate position
:: ③ In order to correctly display quotes and equal signs, in the statement set /p= !str:~0,1!<nul, there is a space after the equal sign, and the backspace key is used

for /f "delims=" %%i in ('findstr /n .* test.txt') do (
set "str=%%i"
setlocal enabledelayedexpansion
set str=!str:*:=!
call :pickup
endlocal
)
pause
goto :eof

:pickup
ping -n 1 127.1>nul
if defined str (
set /p= !str:~0,1!<nul
set str=!str:~1!
goto pickup
)
echo.
goto :eof
尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。
Floor 22 Posted 2007-05-30 18:47 ·  中国 广东 广州 黄埔区 电信
中级用户
★★
Credits 326
Posts 152
Joined 2007-05-04 06:16
19-year member
UID 87412
Gender Male
Status Offline
Hehe... Everyone is a great person here.... I also need to study hard ing
Floor 23 Posted 2008-01-07 15:54 ·  中国 广西 百色 中移铁通
银牌会员
★★★
永远的菜鸟
Credits 1,335
Posts 574
Joined 2007-11-27 12:50
18-year member
UID 103929
Gender Male
From 广西
Status Offline
How to input the backspace key, can anyone tell me, thank you!
Floor 24 Posted 2008-01-08 13:51 ·  中国 浙江 温州 电信
初级用户
★★
Credits 154
Posts 67
Joined 2006-10-31 00:50
19-year member
UID 68933
Gender Male
Status Offline
Collected.. Indeed classic
Floor 25 Posted 2008-01-08 14:31 ·  中国 山东 青岛 联通
初级用户
★★
Credits 107
Posts 60
Joined 2007-11-07 22:03
18-year member
UID 102010
Gender Male
Status Offline
After listening to the moderator's hint, I directly went to floor 21 for testing. What a great person!
Floor 26 Posted 2008-01-30 20:14 ·  中国 香港 新世界电讯
新手上路
Credits 13
Posts 7
Joined 2007-10-04 19:44
18-year member
UID 98894
Gender Male
Status Offline
All are experts! Give a thumbs up!
Floor 27 Posted 2008-03-05 17:46 ·  中国 北京 阿里云BGP数据中心
初级用户
Credits 64
Posts 37
Joined 2007-03-14 03:38
19-year member
UID 81659
Gender Male
Status Offline
All are experts! Let's learn...
Floor 28 Posted 2008-03-05 23:16 ·  中国 云南 玉溪 电信
新手上路
Credits 4
Posts 2
Joined 2008-03-05 15:28
18-year member
UID 112100
Gender Male
Status Offline
This really is pretty good!
Floor 29 Posted 2008-03-20 22:29 ·  中国 湖北 武汉 电信
初级用户
Credits 24
Posts 17
Joined 2008-03-20 22:07
18-year member
UID 113537
Gender Male
Status Offline
Not bad
Floor 30 Posted 2008-03-31 07:07 ·  中国 贵州 黔西南布依族苗族自治州 兴义市 电信
初级用户
Credits 42
Posts 21
Joined 2008-03-31 02:56
18-year member
UID 114505
Gender Male
Status Offline
Great experts, we are extremely admiring. Collected...
Forum Jump: