Page 1 of 1

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

Posted: 05 Nov 2019 15:42
by PAB
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.

Re: Delete row in >> %OUTPUT%.

Posted: 05 Nov 2019 16:03
by aGerman
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

Re: Delete row in >> %OUTPUT%.

Posted: 05 Nov 2019 17:25
by PAB
Here is the code . . .

Code: Select all

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

Re: Delete row in >> %OUTPUT%.

Posted: 05 Nov 2019 18:13
by aGerman
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

Re: Delete row in >> %OUTPUT%.

Posted: 05 Nov 2019 18:19
by Squashman
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.

Re: Delete row in >> %OUTPUT%.

Posted: 05 Nov 2019 18:41
by PAB
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.

Re: Delete row in >> %OUTPUT%.

Posted: 05 Nov 2019 19:00
by PAB
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.

Re: Delete row in >> %OUTPUT%.

Posted: 05 Nov 2019 19:22
by aGerman
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

Re: Delete row in >> %OUTPUT%.

Posted: 06 Nov 2019 03:00
by PAB
Thanks Steffen, it is appreciated.