1.

Solve : Trying to align output?

Answer»

I am working on a batch file where I want it to list stuff about the computer such as computer name, version of windows, disk drive size, etc.  I have the commands to gather the info, and its all going into a textfile that then gets mailed to me.  What I want is it to look neater.

Currently I get...

Computer Name: BERENERD
IP: 192.168.1.125
Version: Microsoft Windows [Version 6.0.6002]

What I want is....

Computer Name:    BERENERD
IP:                          192.168.1.125
Version:                  Microsoft Windows [Version 6.0.6002]

I have been searching for a way to do this and have failed miserably.  I found some posts in this forum from 2010 but it looked like the answer was never given that WOULD work for both XP and later versions of windows (vista, windows 7) any ideas?What you want is a way ton generate a report. Most , if not all, of the commands in DOS or Windows CMD are for working with files s and file names and the attributes of the files.

A delimiter is a symbol used to mark  fields in a record.

Report generation should be done by a suitable application. If the fields  have delimiters you can format a report. Ecell can help you generate a report if the fields, or cells, are in the CSV format. Each value must have a comma to 'delimit' it from another value.

Of course, if you can get it into CSV you can also format in in DOS using the FOR command, which can separate items having delimiters.
Can't be sure about Vista but this might test out okay on XP and Win 7

Code: [Select]echo off
cls
setlocal

for /f "tokens=1* delims=:" %%1 in (trial.txt) do (
    set first=%%1:               .
    echo !first:~0,17!%%2
    )
   
Quote from: Dusty on October 14, 2011, 01:26:06 AM

Code: [Select]echo off
cls
setlocal

for /f "tokens=1* delims=:" %%1 in (trial.txt) do (
    set first=%%1:               .
    echo !first:~0,17!%%2
    )
   

Wasn't sure, but were you going for the setlocal enabledelayedexpansion on the third line? That's needed for your "!first:~0,17!" VARIABLE to work.  Also, I didn't think numbers worked for the FOR variable. I was pretty sure it was letters only, and case sensitivity allowed for a maximum of 52 variables to be set. Is that different in XP?

From the FOR /? in cmd prompt:

FOR %variable IN (set) DO command [command-PARAMETERS]

  %variable  Specifies a single letter replaceable parameter.
  (set)      Specifies a set of one or more files.  Wildcards may be used.
  command    Specifies the command to carry out for each file.
  command-parameters
             Specifies parameters or switches for the specified command.

To use the FOR command in a batch program, specify %%variable instead
of %variable.  Variable names are case sensitive, so %i is different
from %I.

Other than that, all in all, it looks like it would work in Vista and 7 just the same. Quote from: Raven19528 on October 14, 2011, 12:23:27 PM
I didn't think numbers worked for the FOR variable. I was pretty sure it was letters only, and case sensitivity allowed for a maximum of 52 variables to be set. Is that different in XP?

In Windows NT family (2000, XP, Vista, Windows 7, plus Server 2003 & 2008), you can use most of ASCII 33 (!) to 126 (~) the exceptions are, as far as I can see:

34 (") 37 (%) 38 (&) 44(,) 59( 60(<) 61(=) 62(>) 124 )

but the documentation only mentions A-Z and a-z, POSSIBLY to keep things simple for people learning batch scripting.

for example

Code: [Select]C:\>for %# in (a b c) do echo %#
a
b
c

C:\>for %$ in (a b c) do echo %$
a
b
c
Quote from: Raven19528 on October 14, 2011, 12:23:27 PM
Wasn't sure, but were you going for the setlocal enabledelayedexpansion on the third line? That's needed for your "!first:~0,17!" variable to work. 

Oops yes, thank you for the correction, I can only blame the Friday night rums and Cokes for the omission. 

Your other query has been ANSWERED by ST and I can only add that most printable ASCII characters are acceptable in a For loop, including a few of the exceptions noted by ST, altho' there are some which must be Escaped. 

Try this.  If it doesn't work I'll think up some excuse!!  (note the use of the Esc char ^ and other chars " and #):

Code: [Select]echo off
cls
setlocal enabledelayedexpansion

for /f "tokens=1* delims=:" %%^" in (trial.txt) do (
    set first=%%":               .
    echo !first:~0,17!%%#
    )


Discussion

No Comment Found