Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to remove empty lines from CMD output? 1

Status
Not open for further replies.

grofaty

IS-IT--Management
Jan 16, 2003
370
SI
Hi,
I would like to remove empty line from a result ouput.
For example command dir returs the following ouput:
Code:
 Volume in drive C has no label.
 Volume Serial Number is 0CEB-9551

 Directory of C:\

13.09.2007  11:18    <DIR>          .
13.09.2007  11:18    <DIR>          ..
13.09.2007  12:52            11.843 a.txt
13.09.2007  10:27               280 de.bat
24.07.2007  13:26           114.253 def.bat
13.09.2007  11:15             4.749 proc.sql
13.09.2007  10:21               123 run.bat
               6 File(s)        132.799 bytes
               2 Dir(s)  16.136.343.552 bytes free

I would like to remove all useless info and also empty lines. I can remove "Volume in drive C has no label." and other useless info by command:
dir | find /V "Volume" | find /V "Directory" | find /V "File(s)" | find /V "Dir(s)"
The ouput is:
Code:
13.09.2007  11:18    <DIR>          .
13.09.2007  11:18    <DIR>          ..
13.09.2007  12:52            11.843 a.txt
13.09.2007  10:27               280 de.bat
24.07.2007  13:26           114.253 def.bat
13.09.2007  11:15             4.749 proc.sql
13.09.2007  10:21               123 run.bat
The ouput is fine exept there are two empty lines at begenning. How to remove empty lines with CMD?

Thanks,
Grofaty
 
Hi, Grofaty

Add another filter: |find ":"
to keep only lines with colons.

Jock
 
Hi,
thanks.

Is there any other command to remove empty lines in general? In this case command find ":" is solution but what if there is no common character in all lines. For example:
Code:
a

b

c
but bear in mind I don't know what the result will be.

Thanks,
Grofaty
 
> Is there any other command to remove empty lines in general?

I can tell you that the "empty" lines consist of two control characters, namely 0D0A in hex (decimal 013 010).

If you can feed that string to the find command, that should solve your problem.

I've tried putting them between quotes using Alt-013 and Alt-010, but that doesn't work, and I don't know how to escape control characters in Windows.

Perhaps in a batch file?

____________________________________________________
Nikon D200 RawShooter PaintShopProXI Python ooReXX MySQL
 
Hi,
I know the "empty line" has two control characters 0D0A in hex. But how to remove them? This is quite easy in Linux/Unix, but I can't find any idea in Windows.
Thanks,
Grofaty
 
Justin,
thanks a lot. That is solution I was looking for.
Regards,
Grofaty
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top