各位好!首先谢谢你关注我的问题。
具体情况是这样的:
在下在编写一个批处理中想要使用 wbat list 命令提供一个选择分区的界面,下面是批处理中相关的命令(与问题无关的语句已隐去):
(%HD% 表示第几个硬盘,已提前赋值)
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
执行后 temp.txt 文件内容如下:
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%
temp1.txt 内容如下:
: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%
%HD%DiskPar.txt 内容如下:
---------- 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%
这时候 call w.bat list 显示出来的 list 会有两个空行,虽然也有办法可以在处理
%wbat% 返回值的时候正确识别出空行并不做处理,或者返回 list 命令重新显示列表(感觉就是点空行没有什么反应),但总归感觉不理想。
这里请教各位高手:
如何在批处理中删除指定文本文件中的空白行?
另:
这里列出的结果使用的是 Win98 里的 Find.exe (大小 6.50KB)命令,如果使用
Wengier 的超级启动盘中提供的那个 Find.com (大小 2.89KB) 则不会有这两个空行。但那个 Find.com 不知道为什么,在 windows 98 的 DOS 窗口执行的时候大多数情况都正常,偶尔会出现错误(几率比较小),而在纯粹的 DOS 环境下,运行就从没有成功过,出错的现象是:最终的 %HD%DiskPar.txt 文件中只有如下一行:
Invalid drive specification
别的什么也没有了。请高手指教这个错误提示是为什么?
而如果用 win98里的 Find.exe 。则各种环境都从不出错 (但总是有两个空行)
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)