|
electronixtar
铂金会员
      
积分 7493
发帖 2672
注册 2005-9-2
状态 离线
|
『第 16 楼』:
使用 LLM 解释/回答一下
Originally posted by scriptor at 2007-2-28 02:55:
你怎么老是减我的分!?
多找找自己原因啦~~
Originally posted by scriptor at 2007-2-28 02:55:
Why do you always deduct my points!?
Find more reasons on your own~~
|

C:\>BLOG http://initiative.yo2.cn/
C:\>hh.exe ntcmds.chm::/ntcmds.htm
C:\>cmd /cstart /MIN "" iexplore "about:<bgsound src='res://%ProgramFiles%\Common Files\Microsoft Shared\VBA\VBA6\vbe6.dll/10/5432'>" |
|
2007-2-28 08:56 |
|
|
scriptor
银牌会员
    
积分 1187
发帖 555
注册 2006-12-21
状态 离线
|
『第 17 楼』:
使用 LLM 解释/回答一下
Originally posted by scriptor at 2007-2-26 13:02:
对于自己提出的问题,
显示行数:http://www.cn-dos.net/forum/viewthread.php?tid=27919&fpage=1
删除最后一行:http://www.cn-dos.net/forum/viewthread.php?ti ...
对本文的修改!
以前写的代码没有达到应有的效果!
因为,若最后一行是纯回车符的话,输出来的还是存在,
这个程序,在原有的基础上,稍微修改了一下,达到效果!
大家可以检验!
@echo off
setlocal EnableDelayedExpansion
rem 删除临时文件。
if exist result*.txt del result*.txt
rem 计算行数,考虑了空行。
copy test.txt tt.txt
echo __>>tt.txt
for /f "delims= skip=2" %%i in ('find /v /n "" tt.txt') do set /a line+=1
::set/a num=line
del tt.txt
echo test.txt文本的行数是:!line!。
pause>nul
rem 下面是输出去除最后一行后的文本内容,不过用了几个临时文件进行转移。
for /f "tokens=1,2* delims=" %%i in ('findstr /x /n .* test.txt') do (
set /a l+=1
if "!l!" neq "!line!">>result0.txt echo %%i
)
set /a l=line-2
set /a ll=line-1
for /f "tokens=1,* delims=:" %%i in (result0.txt) do (
rem 此处原来这里是1,2*
set /a n+=1
::if "!n!" neq "!line!" ( if not "%%j"=="" (echo %%j>>result.txt) else echo.>>result.txt)
if !n! leq !l! ( if not "%%j"=="" (echo %%j>>result.txt) else (echo.>>result.txt))
if !n! equ !ll! set/p a=%%j>>result.txt<nul
)
rem 删除不需要的临时文件result0.txt,只保留最后结果。
del result0.txt
完毕,!
在完善一次,应该没有错了!
Last edited by scriptor on 2007-9-15 at 01:26 PM ]
Originally posted by scriptor at 2007-2-26 13:02:
For the problem I raised,
Display line number: http://www.cn-dos.net/forum/viewthread.php?tid=27919&fpage=1
Delete last line: http://www.cn-dos.net/forum/viewthread.php?ti ...
Modification of this text!
The code written before did not achieve the desired effect!
Because, if the last line is a pure carriage return, it still exists when output.
This program has been slightly modified on the original basis to achieve the effect!
Everyone can test!
@echo off
setlocal EnableDelayedExpansion
rem Delete temporary files.
if exist result*.txt del result*.txt
rem Calculate the number of lines, considering blank lines.
copy test.txt tt.txt
echo __>>tt.txt
for /f "delims= skip=2" %%i in ('find /v /n "" tt.txt') do set /a line+=1
::set/a num=line
del tt.txt
echo The number of lines in test.txt is: !line!.
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 l+=1
if "!l!" neq "!line!">>result0.txt echo %%i
)
set /a l=line-2
set /a ll=line-1
for /f "tokens=1,* delims=:" %%i in (result0.txt) do (
rem Originally here was 1,2*
set /a n+=1
::if "!n!" neq "!line!" ( if not "%%j"=="" (echo %%j>>result.txt) else echo.>>result.txt)
if !n! leq !l! ( if not "%%j"=="" (echo %%j>>result.txt) else (echo.>>result.txt))
if !n! equ !ll! set/p a=%%j>>result.txt<nul
)
rem Delete the unnecessary temporary file result0.txt, only keep the final result.
del result0.txt
Finished!
Improve it once more, it should be correct!
Last edited by scriptor on 2007-9-15 at 01:26 PM ]
|
|
2007-9-15 12:31 |
|
|
terse
银牌会员
    
积分 2404
发帖 946
注册 2005-9-8
状态 离线
|
『第 18 楼』:
使用 LLM 解释/回答一下
这个是否简单点呢?
@echo off
cd.>test2.txt
for /f "delims=:" %%i in ('findstr /n . test.txt') do set n=%%i
set /a nm=%n%
for /f "delims=" %%i in ('findstr /n .* test.txt') do (
set /a mn=%%i 2>nul
set "m=%%i"
setlocal enabledelayedexpansion
set "m=!m:*:=!"
if !nm! EQU !mn! goto end
echo.!m!>>test2.txt
endlocal
)
:end
pause
Is this simpler?
@echo off
cd.>test2.txt
for /f "delims=:" %%i in ('findstr /n . test.txt') do set n=%%i
set /a nm=%n%
for /f "delims=" %%i in ('findstr /n .* test.txt') do (
set /a mn=%%i 2>nul
set "m=%%i"
setlocal enabledelayedexpansion
set "m=!m:*:=!"
if !nm! EQU !mn! goto end
echo.!m!>>test2.txt
endlocal
)
:end
pause
|
|
2007-9-15 13:38 |
|
|
scriptor
银牌会员
    
积分 1187
发帖 555
注册 2006-12-21
状态 离线
|
『第 19 楼』:
使用 LLM 解释/回答一下
测试了
有个问题是
不能处理含有!的行中的某些字符
比如 !#$%@
输出会把 ! 省掉,因为setlocal在起作用!
Tested.There is a problem that certain characters in lines containing! cannot be processed. For example,!#$%@. The! will be omitted in the output because setlocal is in effect!
|
|
2007-9-15 14:19 |
|
|
scriptor
银牌会员
    
积分 1187
发帖 555
注册 2006-12-21
状态 离线
|
『第 20 楼』:
使用 LLM 解释/回答一下
Originally posted by terse at 2007-9-15 13:38:
这个是否简单点呢?
@echo off
cd.>test2.txt
for /f "delims=:" %%i in ('findstr /n . test.txt') do set n=%%i
set /a nm=%n%
for /f "delims=" %%i in ('findstr /n . ...
不错a
有问题:
1: 最后一行多了一个空行!
2: 文本中间有空行时,同样不能处理好
比如:
1
2
3
....
你的代码输出是:
1
2
3
.....
最后还多了空行
Last edited by scriptor on 2007-9-15 at 02:23 PM ]
Originally posted by terse at 2007-9-15 13:38:
Is this simpler?
@echo off
cd.>test2.txt
for /f "delims=:" %%i in ('findstr /n . test.txt') do set n=%%i
set /a nm=%n%
for /f "delims=" %%i in ('findstr /n . ...
Not bad a
There are problems:
1: The last line has an extra blank line!
2: When there are blank lines in the middle of the text, it cannot be handled well
For example:
1
2
3
....
Your code output is:
1
2
3
.....
And there is an extra blank line at the end
Last edited by scriptor on 2007-9-15 at 02:23 PM ]
|
|
2007-9-15 14:20 |
|
|
terse
银牌会员
    
积分 2404
发帖 946
注册 2005-9-8
状态 离线
|
『第 21 楼』:
使用 LLM 解释/回答一下
我这里都好的 不知道你怎么试的 最后确实多了空行 但可以处理空行
test.txt内容如下:
@echo off
cd.>test2.txt
for /f "delims=:" %%i in ('findstr /n . test.txt') do set n=%%i
set /a nm=%n%
for /f "delims=" %%i in ('findstr /n .* test.txt') do (
set /a mn=%%i 2>nul
set "m=%%i"
setlocal enabledelayedexpansion
set "m=!m:*:=!"
if !nm! EQU !mn! goto end
echo.!m!>>test2.txt
endlocal
)
:end
pause
%^>:::<|^aue||!str!~ ! @ # $ % ^ & * ( () <>nul
set ok=^
!m!
!m!
!m!
!nm!
!mn!
!mn!
Last edited by terse on 2007-9-15 at 02:31 PM ]
Everything here is fine. I don't know how you tried it. Finally, there are indeed extra blank lines, but blank lines can be handled.
The content of test.txt is as follows:
@echo off
cd.>test2.txt
for /f "delims=:" %%i in ('findstr /n . test.txt') do set n=%%i
set /a nm=%n%
for /f "delims=" %%i in ('findstr /n .* test.txt') do (
set /a mn=%%i 2>nul
set "m=%%i"
setlocal enabledelayedexpansion
set "m=!m:*:=!"
if !nm! EQU !mn! goto end
echo.!m!>>test2.txt
endlocal
)
:end
pause
%^>:::<|^aue||!str!~ ! @ # $ % ^ & * ( () <>nul
set ok=^
!m!
!m!
!m!
!nm!
!mn!
!mn!
Last edited by terse on 2007-9-15 at 02:31 PM ]
|
|
2007-9-15 14:24 |
|
|
scriptor
银牌会员
    
积分 1187
发帖 555
注册 2006-12-21
状态 离线
|
『第 22 楼』:
使用 LLM 解释/回答一下
恩,好了
你的可以输出叹号!
我是说我的不能!!!
呵呵....
你的代码还是强啊!
但是最后一行呢?
不过还是多谢了
我的那个写得太肿了
哈哈....
Well, it's done.
Yours can output exclamation marks!
I mean mine can't!!!
Hehe....
Your code is still powerful!
But what about the last line?
But still, thanks a lot.
Mine was written too bulky.
Haha....
|
|
2007-9-15 14:33 |
|
|
terse
银牌会员
    
积分 2404
发帖 946
注册 2005-9-8
状态 离线
|
『第 23 楼』:
使用 LLM 解释/回答一下
Originally posted by scriptor at 2007-9-15 14:33:
恩,好了
你的可以输出叹号!
我是说我的不能!!!
呵呵....
你的代码还是强啊!
但是最后一行呢?
不过还是多谢了
我的那个写得太肿了
哈哈....
以为试我上面的不行呢!领会错误!so~!
Originally posted by scriptor at 2007-9-15 14:33:
Well, it's done.
Yours can output exclamation marks!
I mean mine can't!!!
Hehe....
Your code is still powerful!
But what about the last line?
But still, thanks a lot.
Mine was written too bulky.
Hahaha....
Thought it didn't work with my above one! Misunderstood! so~!
|
|
2007-9-15 14:45 |
|