中国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-08-10 17:38
47,811 topics / 349,897 posts / today 0 new / 48,256 members
DOS疑难解答 & 问题讨论 (解答室) » Ask: How to delete blank lines in a specified text file in a batch processing?
Printable Version  3,609 / 4
Floor1 Tamm Posted 2004-04-18 00:00
中级用户 Posts 64 Credits 397
Hello everyone! First of all, thank you for paying attention to my question.

The specific situation is like this:

I want to use the wbat list command to provide an interface for selecting partitions in a batch processing. The following are the relevant commands in the batch processing (the statements irrelevant to the question have been omitted):

(%HD% means which hard disk, has been assigned in advance)

gdisk %HD% >%temp%\temp.txt
ECHO :sign >%temp%\temp1.txt
find /i "primary" %temp%\temp.txt >> %temp%\temp1.txt
find /i "logical" %temp%\temp.txt >> %temp%\temp1.txt
find /i /v "TXT" %temp%\temp1.txt >%temp%\%HD%DiskPar.txt
::del %temp%\temp*.txt
call w.bat list @%temp%\%HD%DiskPar.txt :sign
:THE END


After execution, the content of the temp.txt file is as follows:
Disk Partitions Cylinders Heads Sectors Mbytes Model
1 10 9729 255 63 76319.1 Unavailable

Partition Status Type Volume Label Mbytes System Usage
C: 1 A PRIMARY 98 2000.2 FAT32 3%
2 EXTENDED 74316.3 97%
3 LOGICAL 4000.5 NTFS/HPFS 5%
4 LOGICAL 15029.5 NTFS/HPFS 20%
5 LOGICAL 10001.4 NTFS/HPFS 13%
6 LOGICAL 4000.5 NTFS/HPFS 5%
7 LOGICAL 4000.5 NTFS/HPFS 5%
D: 8 LOGICAL BACKUP 12276.2 FAT32 16%
E: 9 LOGICAL TEMP 5004.6 FAT32 7%
10 LOGICAL 20002.8 NTFS/HPFS 26%

The content of temp1.txt is as follows:
:sign

---------- C:\WINDOWS\TEMP\temp.txt
C: 1 A PRIMARY 98 2000.2 FAT32 3%

---------- C:\WINDOWS\TEMP\temp.txt
3 LOGICAL 4000.5 NTFS/HPFS 5%
4 LOGICAL 15029.5 NTFS/HPFS 20%
5 LOGICAL 10001.4 NTFS/HPFS 13%
6 LOGICAL 4000.5 NTFS/HPFS 5%
7 LOGICAL 4000.5 NTFS/HPFS 5%
D: 8 LOGICAL BACKUP 12276.2 FAT32 16%
E: 9 LOGICAL TEMP 5004.6 FAT32 7%
10 LOGICAL 20002.8 NTFS/HPFS 26%


The content of %HD%DiskPar.txt is as follows:

---------- C:\WINDOWS\TEMP\temp1.txt
:sign

C: 1 A PRIMARY 98 2000.2 FAT32 3%

3 LOGICAL 4000.5 NTFS/HPFS 5%
4 LOGICAL 15029.5 NTFS/HPFS 20%
5 LOGICAL 10001.4 NTFS/HPFS 13%
6 LOGICAL 4000.5 NTFS/HPFS 5%
7 LOGICAL 4000.5 NTFS/HPFS 5%
D: 8 LOGICAL BACKUP 12276.2 FAT32 16%
E: 9 LOGICAL TEMP 5004.6 FAT32 7%
10 LOGICAL 20002.8 NTFS/HPFS 26%


At this time, call w.bat list shows that there are two blank lines in the list. Although there is a way to correctly identify and not process blank lines when processing the %wbat% return value, or to return the list command to display the list again (it feels like clicking on a blank line has no response), but it always feels unsatisfactory.

Here, I ask all the experts: How to delete the blank lines in the specified text file in the batch processing?

In addition:

The results listed here use the Find.exe (size 6.50KB) command in Win98. If the Find.com (size 2.89KB) provided in Wengier's super startup disk is used, there will be no these two blank lines. But I don't know why that Find.com, when executed in the DOS window of windows 98, is mostly normal, and occasionally an error occurs (the probability is relatively small), while in a pure DOS environment, it has never run successfully. The error phenomenon is: The final %HD%DiskPar.txt file only has the following line:
Invalid drive specification
There is nothing else. Please ask the expert to teach why this error prompt is?
And if you use Find.exe in win98. Then all kinds of environments never make mistakes (but there are always two blank lines)














Floor2 Climbing Posted 2004-04-18 00:00
铂金会员 Posts 2,753 Credits 6,962 From 河北保定
You can use Horst's Listmod or lmod to remove blank lines.

type %HD%DiskPar.txt | listmod $*
or
type %HD%DiskPar.txt | lmod /L3*

The latter command can even remove the line with temp1.txt.
Floor3 Tamm Posted 2004-04-19 00:00
中级用户 Posts 64 Credits 397
The following is a quote from Climbing on 2004-4-18 21:13:00:
Both Horst's Listmod or lmod can be used to remove blank lines.

type %HD%DiskPar.txt | listmod $*
or
type %HD%DiskPar.txt | lmod /L3* 

The latter command can also remove the line with temp1.txt.


Thank you very much, Mr. Climbing, for your guidance.
Because I have only recently started learning to use DOS commands and my level is very basic. I know very little about DOS tools (I'm studying hard...). I've never used "Horst's Listmod or lmod..." and I'm really sorry. I've searched the forum for a long time and haven't found relevant information. Many links in the forum seem to be invalid (I don't know if it's my network problem, but I always can't open them)
So I still want to continue to trouble you to guide:
Where can I get this Horst tool?
Is it possible for me to learn to use it from the prompts (or help) information that the tool itself has?

(My English level is also very poor, but I'm not very lazy. Recently, I spent about ten days basically mastering its use through the DEMO in WBAT. Most of the time was spent translating those English texts ^_^ )
Floor4 Climbing Posted 2004-04-19 00:00
铂金会员 Posts 2,753 Credits 6,962 From 河北保定
WBAT is a product of Horst (full name Horst Schaeffer). If you know where to download WBAT, then you can download listmod or lmod in the same place.

Similarly, search with Google using the keyword Horst listmod, and you can also find many download sites.

Finally, I provide Horst's homepage:
http://home.mnet-online.de/horst.muc/
Floor5 Tamm Posted 2004-04-19 00:00
中级用户 Posts 64 Credits 397
Thanks a lot! These are exactly what I want.
Studying hard...

BTW: My WBAT is downloaded from another third-party site. Since I just got it not long ago, I've been researching its DEMO. I haven't visited its "home" yet.
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023