![]() |
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-08-05 19:25 |
48,039 topics / 350,124 posts / today 2 new / 48,251 members |
| DOS批处理 & 脚本技术(批处理室) » [Original]Finally solved - display line number & delete last line |
| Printable Version 3,116 / 22 |
| Floor1 scriptor | Posted 2007-02-26 13:02 |
| 银牌会员 Posts 555 Credits 1,187 | |
|
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 ] |
|
| Floor2 slore | Posted 2007-02-26 13:15 |
| 铂金会员 Posts 2,478 Credits 5,212 | |
|
The output with /n from findstr can contain blank lines. You read it again... You thought of this when you first posted it, it's too cumbersome... It wasn't posted because it required 2 times, so finally it's suggested that you use a script, which can be read once.
|
|
| Floor3 scriptor | Posted 2007-02-26 13:22 |
| 银牌会员 Posts 555 Credits 1,187 | |
|
Floor 2
The output of findstr with /n can include empty lines, read it again... Indeed, it can. Doesn't it work for you? Need twice One is find and the other is findstr Okay. Can you make it clear? Where is the problem!? |
|
| Floor4 scriptor | Posted 2007-02-26 13:23 |
| 银牌会员 Posts 555 Credits 1,187 | |
|
Then I'll post a code with only one find, truly reading only once:
[ Last edited by scriptor on 2007-2-26 at 12:32 AM ] |
|
| Floor5 scriptor | Posted 2007-02-26 13:26 |
| 银牌会员 Posts 555 Credits 1,187 | |
|
This code is to judge the lines with only one carriage return symbol, and the processing is: if it is a carriage return and line feed, then echo., if not, then output the original text. [ Last edited by scriptor on 2007-2-26 at 12:31 AM ] |
|
| Floor6 scriptor | Posted 2007-02-26 13:37 |
| 银牌会员 Posts 555 Credits 1,187 | |
|
But if there is a line consisting entirely of spaces, there is a problem. For example:
After conversion, the output is "echo is in the off state." How to solve it? |
|
| Floor7 slore | Posted 2007-02-26 13:42 |
| 铂金会员 Posts 2,478 Credits 5,212 | |
|
Alas, it looks troublesome. If the script is simple, use the script to write... use the most suitable and most efficient code... personal principle...
It's a bit far-fetched to force p to process the text (not to say it can't be done) |
|
| Floor8 scriptor | Posted 2007-02-26 14:01 |
| 银牌会员 Posts 555 Credits 1,187 | |
|
I won't write VBS and JS. Can you write one for me??
|
|
| Floor9 slore | Posted 2007-02-26 14:24 |
| 铂金会员 Posts 2,478 Credits 5,212 | |
|
```vb
Const ForReading = 1 Const ForWriting = 2 Dim strText, strNewText, OutStr Set objFSO = CreateObject("Scripting.FileSystemObject") Set objFile = objFSO.OpenTextFile("d:\slorelee\Desktop\1.txt", ForReading) strText = objFile.ReadAll objFile.Close strNewText = Split(strText, vbCrlf) MsgBox "There are " & CStr(Ubound(strNewText) + 1) & " lines" strNewText(Ubound(strNewText)) = Empty OutStr = Join(strNewText, vbCrlf) OutStr = Mid(OutStr, 1, Len(OutStr) - 2) Set objFile = objFSO.OpenTextFile("d:\slorelee\Desktop\2.txt", ForWriting, True) objFile.Write OutStr objFile.Close ``` |
|
| Floor10 vkill | Posted 2007-02-26 16:52 |
| 金牌会员 Posts 1,744 Credits 4,103 From 甘肃.临泽 | |
Originally posted by scriptor at 2007-2-26 14:01: For file processing, it's better to use sed and awk. |
|
| Floor11 slore | Posted 2007-02-27 01:32 |
| 铂金会员 Posts 2,478 Credits 5,212 | |
Originally posted by vkill at 2007-2-26 03:52: The script is not lazy... and it's non-third-party |
|
| Floor12 scriptor | Posted 2007-02-28 02:55 |
| 银牌会员 Posts 555 Credits 1,187 | |
Originally posted by scriptor at 2007-2-26 00:02: Why do you always deduct my points!? |
|
| Floor13 namejm | Posted 2007-02-28 03:19 |
| 荣誉版主 Posts 1,737 Credits 5,226 From 成都 | |
|
My deduction reasons are clearly stated in the moderation records. If I often deduct points from you, possible reasons are:
1. You often write titles very vaguely; 2. You often post water content. I'm not the only one who deducts points. Many people have received punishments. If there is any unfair handling, please post in the "Feedback & User Communication" section. |
|
| Floor14 everest79 | Posted 2007-02-28 05:45 |
| 金牌会员 Posts 1,127 Credits 2,564 | |
Originally posted by namejm at 2007-2-27 02:19 PM: :D:D:D:D:D Fortunately |
|
| Floor15 everest79 | Posted 2007-02-28 06:20 |
| 金牌会员 Posts 1,127 Credits 2,564 | |
|
```
for /f "delims=:" %%i in ('findstr /n . readme.txt') do set /a num=%%i-1 for /f "tokens=*" %%i in ('more readme.txt +%num%') do set xxx=%%i type readme.txt|find /v "%xxx%">readme2.txt&&echo %num% ``` I also wrote one |
|
| 1 2 Next |
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |