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:24
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Discussion] Output the content of the specified line with special characters preserved to the greatest extent possible DigestI View 19,308 Replies 32
Floor 31 Posted 2008-12-23 01:30 ·  中国 广东 深圳 电信
初级用户
Credits 48
Posts 20
Joined 2005-10-14 15:16
20-year member
UID 43494
Gender Male
Status Offline
Originally posted by namejm at 2007-5-17 21:14:
  The most perfect code is as follows (from the code of bjsh on floor 23, I only made a few changes):

  Code 3:
CODE:
--------------------------------------------------------------------------------

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


Learned, an error occurred when running, but the output txt is correct!

[ Last edited by different on 2008-12-23 at 01:43 ]
Floor 32 Posted 2009-12-03 21:14 ·  中国 北京 联通
初级用户
Credits 39
Posts 27
Joined 2007-09-10 17:46
18-year member
UID 97038
Gender Male
Status Offline
Wonderful. I want to add something, not sure if it's correct.

`findstr /n .* test.txt` is to find all lines and prefix each line with a line number like "1:".

So in the subsequent loop, there is such a line: `set var=!var:*:=!` to delete a batch of line numbers like "1:".

If there is any incorrect place, please correct it!
Floor 33 Posted 2009-12-09 19:03 ·  中国 重庆 电信
初级用户
Credits 20
Posts 11
Joined 2009-12-05 17:26
16-year member
UID 155977
Gender Male
Status Offline
Two words, admire, 23rd floor, oh my god...
Forum Jump: