For the question I raised,
Show line number: http://www.cn-dos.net/forum/viewthread.php?tid=27919&fpage=1
Delete the last line: http://www.cn-dos.net/forum/viewthread.php?tid=27920&fpage=1
Finally all solved
You can test special characters more, and see if the result is correct.
Thanks.
Please criticize and correct if there are any problems.
[ Last edited by namejm on 2007-2-27 at 02:12 PM ]
Show line number: http://www.cn-dos.net/forum/viewthread.php?tid=27919&fpage=1
Delete the last line: http://www.cn-dos.net/forum/viewthread.php?tid=27920&fpage=1
Finally all solved
@echo off
setlocal EnableDelayedExpansion
rem Delete temporary files.
if exist result*.txt del result*.txt
rem Calculate the number of lines, considering blank lines.
for /f "delims=" %%i in ('find /v /n "" test.txt') do set /a line+=1
set/a num=line-1
echo The number of lines in test.txt is: !num!.
pause>nul
rem The following is to output the text content after removing the last line, but several temporary files are used for transfer.
for /f "tokens=1,2* delims=" %%i in ('findstr /x /n .* test.txt') do (
set /a n+=1
if "!n!" neq "!line!">>result0.txt echo %%i
)
for /f "tokens=1,2* delims=:" %%i in (result0.txt) do (
set /a n+=1
if "!n!" neq "!line!" ( if not "%%j"=="" (echo %%j>>result.txt) else echo.>>new2.txt)
)
rem Delete the unnecessary temporary file result0.txt, only keep the final result.
del result0.txt
You can test special characters more, and see if the result is correct.
Thanks.
Please criticize and correct if there are any problems.
[ Last edited by namejm on 2007-2-27 at 02:12 PM ]
Recent Ratings for This Post
( 1 in total)
Click for details
| Rater | Score | Time |
|---|---|---|
| namejm | -2 | 2007-02-27 01:52 |
