中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-09-23 12:23
47,812 topics / 349,917 posts / today 0 new / 48,273 members
DOS批处理 & 脚本技术(批处理室) » [Discussion] Output the content of the specified line with special characters preserved to the greatest extent possible
Printable Version  21,603 / 32
Floor31 different Posted 2008-12-23 01:30
初级用户 Posts 20 Credits 48
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 ]
Floor32 bjjgq Posted 2009-12-03 21:14
初级用户 Posts 27 Credits 39
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!
Floor33 icebat Posted 2009-12-09 19:03
初级用户 Posts 11 Credits 20
Two words, admire, 23rd floor, oh my god...
Prev  1 2 3
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023