[SOLVED] Delete row in >> %OUTPUT%.

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
PAB
Posts: 57
Joined: 12 Aug 2019 13:57

[SOLVED] Delete row in >> %OUTPUT%.

#1 Post by PAB » 05 Nov 2019 15:42

Good evening,

I have a batch script that outputs to a file, for example . . .
echo Title: %var1% >> %OUTPUT%
echo Title: %var2% >> %OUTPUT%
echo Title: %var3% >> %OUTPUT%
It can leave several blank lines in between even though there are none in the code.
Now I am pretty sure the answer is going to be NO, but, is there anyway to delete these lines so there is only one line between the output?

Thanks in advance, Paul.
Last edited by PAB on 07 Nov 2019 09:28, edited 1 time in total.

aGerman
Expert
Posts: 3763
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Delete row in >> %OUTPUT%.

#2 Post by aGerman » 05 Nov 2019 16:03

Try to find the cause rather than fighting the effects.
If you have empty lines then your variables contain new line characters. How do you assign the values of these variables and where are they coming from?

Steffen

PAB
Posts: 57
Joined: 12 Aug 2019 13:57

Re: Delete row in >> %OUTPUT%.

#3 Post by PAB » 05 Nov 2019 17:25

Here is the code . . .

Code: Select all

wmic logicaldisk get deviceid, volumename, description | more >> %OUTPUT%
echo list volume | diskpart >> "%OUTPUT%
Thanks.

aGerman
Expert
Posts: 3763
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Delete row in >> %OUTPUT%.

#4 Post by aGerman » 05 Nov 2019 18:13

FOR /F loops will remove empty lines for you before they get written to the file.

Code: Select all

>>%OUTPUT% (for /f "delims=" %%i in ('wmic logicaldisk get deviceid^,volumename^,description') do for /f "delims=" %%j in ("%%i") do echo %%j)
>>%OUTPUT% echo(
>>%OUTPUT% (for /f "delims=" %%i in ('echo list volume^|diskpart') do echo %%i)
The second line adds an empty line between the outputs of the two commands.

Steffen

Squashman
Expert
Posts: 4114
Joined: 23 Dec 2011 13:59

Re: Delete row in >> %OUTPUT%.

#5 Post by Squashman » 05 Nov 2019 18:19

PAB wrote:
05 Nov 2019 15:42
Good evening,

I have a batch script that outputs to a file, for example . . .
echo Title: %var1% >> %OUTPUT%
echo Title: %var2% >> %OUTPUT%
echo Title: %var3% >> %OUTPUT%
It can leave several blank lines in between even though there are none in the code.
Now I am pretty sure the answer is going to be NO, but, is there anyway to delete these lines so there is only one line between the output?

Thanks in advance, Paul.
In the future you should ALWAYS provide a verifiable example of the code you are using to produce the problem. Time is a precious resource for everyone who helps on the forums. Your question could have been answered with one response instead of multiple.

PAB
Posts: 57
Joined: 12 Aug 2019 13:57

Re: Delete row in >> %OUTPUT%.

#6 Post by PAB » 05 Nov 2019 18:41

Squashman wrote:
05 Nov 2019 18:19

In the future you should ALWAYS provide a verifiable example of the code you are using to produce the problem. Time is a precious resource for everyone who helps on the forums. Your question could have been answered with one response instead of multiple.
I am sorry Squashman, I will keep that in mind for the future.

PAB
Posts: 57
Joined: 12 Aug 2019 13:57

Re: Delete row in >> %OUTPUT%.

#7 Post by PAB » 05 Nov 2019 19:00

aGerman wrote:
05 Nov 2019 18:13
FOR /F loops will remove empty lines for you before they get written to the file.

Code: Select all

>>%OUTPUT% (for /f "delims=" %%i in ('wmic logicaldisk get deviceid^,volumename^,description') do for /f "delims=" %%j in ("%%i") do echo %%j)
>>%OUTPUT% echo(
>>%OUTPUT% (for /f "delims=" %%i in ('echo list volume^|diskpart') do echo %%i)
The second line adds an empty line between the outputs of the two commands.

Steffen
Thank you for that. I would never have worked that out in a million years!

I wish I had learnt programming in the past [too old now]!
The only thing that I have outstanding on this now is extracting two pieces of information. I have managed to do it using systeminfo but I was really trying to do it using wmic. I have spent quite a bit of the day on it as I am off work waiting for two operations!

Code: Select all

systeminfo 2>NUL | FindSTR /b /C:"OS Configuration": >> %OUTPUT%
systeminfo 2>NUL | FindSTR /b /C:"System Locale": >> %OUTPUT%
Which produces . . .

Code: Select all

OS Configuration:    Standalone Workstation
System Locale:       en-gb;English (United Kingdom)
I have noticed that using systeminfo takes quite a while as opposed to using wmic.

I just can't get this data from wmic!

Thanks in advance.

aGerman
Expert
Posts: 3763
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Delete row in >> %OUTPUT%.

#8 Post by aGerman » 05 Nov 2019 19:22

I don't know all the WMI classes and their members by heart. Good point to start in your case is that site:
https://docs.microsoft.com/en-us/window ... em-classes
Just have a look at the classes of your interest and see if one of them has the members you are looking for.

Steffen

PAB
Posts: 57
Joined: 12 Aug 2019 13:57

Re: Delete row in >> %OUTPUT%.

#9 Post by PAB » 06 Nov 2019 03:00

Thanks Steffen, it is appreciated.

Post Reply