China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-06-20 14:08
中国DOS联盟论坛 » DOS疑难解答 & 问题讨论 (解答室) » Ask: How to delete blank lines in a specified text file in a batch processing? View 3,489 Replies 4
Original Poster Posted 2004-04-18 00:00 ·  中国 湖南 株洲 电信
中级用户
★★
Credits 397
Posts 64
Joined 2004-04-18 00:00
22-year member
UID 22767
Gender Male
Status Offline
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)














Floor 2 Posted 2004-04-18 00:00 ·  中国 河北 石家庄 联通
铂金会员
★★★★
网络独行侠
Credits 6,962
Posts 2,753
Joined 2003-04-16 00:00
23-year member
UID 1565
Gender Male
From 河北保定
Status Offline
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.
偶只喜欢回答那些标题和描述都很清晰的帖子!
如想解决问题,请认真学习“这个帖子”和“这个帖子”并努力遵守,如果可能,请告诉更多的人!
Floor 3 Posted 2004-04-19 00:00 ·  中国 湖南 株洲 电信
中级用户
★★
Credits 397
Posts 64
Joined 2004-04-18 00:00
22-year member
UID 22767
Gender Male
Status Offline
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 ^_^ )
Floor 4 Posted 2004-04-19 00:00 ·  中国 河北 石家庄 联通
铂金会员
★★★★
网络独行侠
Credits 6,962
Posts 2,753
Joined 2003-04-16 00:00
23-year member
UID 1565
Gender Male
From 河北保定
Status Offline
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/
偶只喜欢回答那些标题和描述都很清晰的帖子!
如想解决问题,请认真学习“这个帖子”和“这个帖子”并努力遵守,如果可能,请告诉更多的人!
Floor 5 Posted 2004-04-19 00:00 ·  中国 湖南 株洲 电信
中级用户
★★
Credits 397
Posts 64
Joined 2004-04-18 00:00
22-year member
UID 22767
Gender Male
Status Offline
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.
Forum Jump: