putting in a line break

  • Thread starter Thread starter Jim in Arizona
  • Start date Start date
J

Jim in Arizona

How do I put in a line break, like in the following script:

ipconfig > "%userprofile%\Desktop\COMPUTER INFO.txt"
echo . >> "%userprofile%\Desktop\COMPUTER INFO.txt"
echo . >> "%userprofile%\Desktop\COMPUTER INFO.txt"
echo ============================================================== >>
"%userprofile%\Desktop\COMPUTER INFO.txt"
echo . >> "%userprofile%\Desktop\COMPUTER INFO.txt"
echo . >> "%userprofile%\Desktop\COMPUTER INFO.txt"
echo COMPUTER NAME >> "%userprofile%\Desktop\COMPUTER INFO.txt"
echo -------------------- >> "%userprofile%\Desktop\COMPUTER INFO.txt"
hostname >> "%userprofile%\Desktop\COMPUTER INFO.txt"

I want to replace the periods with a space, if possible.
And if there is a better way to make this script, that would be better
to. Perhaps, better looking output? ;) Is there a way to just get the IP
address without the other IP info?

TIA,
Jim
 
Jim said:
How do I put in a line break, like in the following script:

ipconfig > "%userprofile%\Desktop\COMPUTER INFO.txt"
echo . >> "%userprofile%\Desktop\COMPUTER INFO.txt"
echo . >> "%userprofile%\Desktop\COMPUTER INFO.txt"
echo ============================================================== >>
"%userprofile%\Desktop\COMPUTER INFO.txt"
echo . >> "%userprofile%\Desktop\COMPUTER INFO.txt"
echo . >> "%userprofile%\Desktop\COMPUTER INFO.txt"
echo COMPUTER NAME >> "%userprofile%\Desktop\COMPUTER INFO.txt"
echo -------------------- >> "%userprofile%\Desktop\COMPUTER INFO.txt"
hostname >> "%userprofile%\Desktop\COMPUTER INFO.txt"

I want to replace the periods with a space, if possible.
And if there is a better way to make this script, that would be better
to. Perhaps, better looking output? ;) Is there a way to just get the IP
address without the other IP info?

TIA,
Jim

Hi, Jim,

Change 'echo .' to 'echo.' to echo a blank line to the file.

For just the IP Address, you could do

for /f "tokens=2 delims=:" %%a in (
'ipconfig /all ^| find "IP Address"'
) do @echo/IP Address is %%a
 
I'm not familiar with any of that batch coding. I tried to work it to
get me the host name using the same stuff, like so:

for /f "tokens=2 delims=:" %%a in (
'hostname'
) do @echo/Your Computer Name Is: %%a >> "%userprofile%\Desktop\COMPUTER
INFO.rtf"

That didn't do me any good. It just doesn't show up. I tried putting it
right underneath your code so the output would look like:

Your IP Address Is: 192.168.1.100
Your Hostname Is: ComputerA

Is there a VB Scripting version that will show those two things in a pop
up window where you have to click Ok to make it go away? I should
probably ask the vbscript group for that one huh?

My goal is to put a link on our internal website that will run either
the batch or vbscript to give the employee the IP address and hostname
of their computer so we don't have to ask them to click on Start, then
Run, then type in CMD then type in ipconfig .. and so on. It would be so
much easier just to have it done for them then all they have to do is
give us the number from the file on their desktop or the pop up box from
running the vbscript.
 
Jim said:
I'm not familiar with any of that batch coding. I tried to work it to
get me the host name using the same stuff, like so:

for /f "tokens=2 delims=:" %%a in (
'hostname'
) do @echo/Your Computer Name Is: %%a >> "%userprofile%\Desktop\COMPUTER
INFO.rtf"

echo/Your Computer Name Is: %computername% >> ....
That didn't do me any good. It just doesn't show up. I tried putting it
right underneath your code so the output would look like:

Your IP Address Is: 192.168.1.100
Your Hostname Is: ComputerA

Is there a VB Scripting version that will show those two things in a pop
up window where you have to click Ok to make it go away? I should
probably ask the vbscript group for that one huh?

Yes. But you could do this equally well with a batch file.

==========begin file C:\cmd\test\ShowUserInfo.cmd ==========
001. @echo off
002. mode con cols=45 lines=8
003. color ce
004. for /f "tokens=2 delims=:" %%a in (
005. 'ipconfig /all ^| find "IP Address"'
006. ) do echo/IP Address: %%a
007. echo/Computername: %computername%
008. echo/
009. echo/ (press ANY KEY to EXIT)
010. pause>nul
==========end file C:\cmd\test\ShowUserInfo.cmd ==========

Create a shortcut to execute the preceding. In the Target field,
enter

%comspec% /c c:\cmd\test\ShowIPAddress.cmd

(or whatever directory you choose to put the batch file in).
 
Phil said:
echo/Your Computer Name Is: %computername% >> ....



Yes. But you could do this equally well with a batch file.

==========begin file C:\cmd\test\ShowUserInfo.cmd ==========
001. @echo off
002. mode con cols=45 lines=8
003. color ce
004. for /f "tokens=2 delims=:" %%a in (
005. 'ipconfig /all ^| find "IP Address"'
006. ) do echo/IP Address: %%a
007. echo/Computername: %computername%
008. echo/
009. echo/ (press ANY KEY to EXIT)
010. pause>nul
==========end file C:\cmd\test\ShowUserInfo.cmd ==========

Create a shortcut to execute the preceding. In the Target field,
enter

%comspec% /c c:\cmd\test\ShowIPAddress.cmd

Sorry, it should say 'c:\cmd\test\ShowUserInfo.cmd' in the preceding
line (or whatever you decide to name the batch file).
 
Jim said:
I'm not familiar with any of that batch coding. I tried to work it to
get me the host name using the same stuff, like so:

for /f "tokens=2 delims=:" %%a in (
'hostname'
) do @echo/Your Computer Name Is: %%a >> "%userprofile%\Desktop\COMPUTER
INFO.rtf"

That didn't do me any good. It just doesn't show up. I tried putting it
right underneath your code so the output would look like:

Your IP Address Is: 192.168.1.100
Your Hostname Is: ComputerA

Is there a VB Scripting version that will show those two things in a pop
up window where you have to click Ok to make it go away? I should
probably ask the vbscript group for that one huh?

My goal is to put a link on our internal website that will run either
the batch or vbscript to give the employee the IP address and hostname
of their computer so we don't have to ask them to click on Start, then
Run, then type in CMD then type in ipconfig .. and so on. It would be so
much easier just to have it done for them then all they have to do is
give us the number from the file on their desktop or the pop up box from
running the vbscript.

Here's a simple vbscript example, also being executed from a batch file:

==========begin file C:\cmd\test\WSHShowUserInfo.cmd ==========
01. @echo off
02. for /f "tokens=2 delims=:" %%a in (
03. 'ipconfig /all ^| find "IP Address"'
04. ) do set IPAddress=%%a
05. echo>c:\temp\WSHUInfo.vbs Result = MsgBox("IP Address: %IPAddress%"
^& (Chr(13) ^& Chr(10)) ^& "Computer name: %computername%", 0, "User Info")
06. cscript //nologo c:\temp\WSHUinfo.vbs
==========end file C:\cmd\test\WSHShowUserInfo.cmd ==========

(Watch out for wrapped lines!)
 
@echo off
setlocal ENABLEDELAYEDEXPANSION
for /f "tokens=1* Delims=:" %%a in ('ipconfig^|findstr "Ethernet Address"') do (
set work=%%a:
if "!work:~0,16!" EQU "Ethernet adapter" set NWK=!work!
if "!work:~0,18!" EQU " IP Address" set NWK=!NWK!%%b
)
@echo %NWK%>"%userprofile%\Desktop\COMPUTER INFO.txt"
for /f "Tokens=*" %%a in ('hostname') do (
@echo COMPUTER NAME: %%a>>"%userprofile%\Desktop\COMPUTER INFO.txt"
)
endlocal

How do I put in a line break, like in the following script:

ipconfig > "%userprofile%\Desktop\COMPUTER INFO.txt"
echo . >> "%userprofile%\Desktop\COMPUTER INFO.txt"
echo . >> "%userprofile%\Desktop\COMPUTER INFO.txt"
echo ============================================================== >>
"%userprofile%\Desktop\COMPUTER INFO.txt"
echo . >> "%userprofile%\Desktop\COMPUTER INFO.txt"
echo . >> "%userprofile%\Desktop\COMPUTER INFO.txt"
echo COMPUTER NAME >> "%userprofile%\Desktop\COMPUTER INFO.txt"
echo -------------------- >> "%userprofile%\Desktop\COMPUTER INFO.txt"
hostname >> "%userprofile%\Desktop\COMPUTER INFO.txt"

I want to replace the periods with a space, if possible.
And if there is a better way to make this script, that would be better
to. Perhaps, better looking output? ;) Is there a way to just get the IP
address without the other IP info?

TIA,
Jim

Jerold Schulman
Windows Server MVP
JSI, Inc.
http://www.jsiinc.com
http://www.jsifaq.com
 
Thanks for all the help, Phil.

I wish there was some online manual somewhere that taught all this batch
stuff. The MSDN articles are limited in what they teach. They just give
you some basic syntax and not much more.

I'll put your code example(s) to good use!

Jim
 
Thanks for the example, Jerold.

I use to visit your site all the time (jsiinc). It's been a while and I
had lost the address. Thanks for reminding me (in your signature).

Jim
 
Phil said:
==========begin file C:\cmd\test\ShowUserInfo.cmd ==========
004. for /f "tokens=2 delims=:" %%a in (
005. 'ipconfig /all ^| find "IP Address"'
006. ) do echo/IP Address: %%a

Which gives raise to a very similar
133) How do I get the current IP address, number and name?

@echo off & setlocal enableextensions
::
:: Get the current IP
for /f "tokens=2 delims=:" %%i in (
'ipconfig /all^|find "IP Address"'
) do set ip=%%i
set ip=%ip: =%
echo %ip%
::
:: Look up the IP address on the name server
for /f "tokens=2 delims=:" %%n in (
'nslookup %ip%^|find "Name:"'
) do set name=%%n
set name=%name: =%
echo %name%
endlocal & goto :EOF

The output might be e.g.
D:\TEST>cmdfaq
193.166.122.2
reimari.uwasa.fi

All the best, Timo
 
Jim in Arizona said:
How do I put in a line break, like in the following script:

ipconfig > "%userprofile%\Desktop\COMPUTER INFO.txt"
echo . >> "%userprofile%\Desktop\COMPUTER INFO.txt"
echo . >> "%userprofile%\Desktop\COMPUTER INFO.txt"
echo ============================================================== >>
"%userprofile%\Desktop\COMPUTER INFO.txt"
echo . >> "%userprofile%\Desktop\COMPUTER INFO.txt"
echo . >> "%userprofile%\Desktop\COMPUTER INFO.txt"
echo COMPUTER NAME >> "%userprofile%\Desktop\COMPUTER INFO.txt"
echo -------------------- >> "%userprofile%\Desktop\COMPUTER INFO.txt"
hostname >> "%userprofile%\Desktop\COMPUTER INFO.txt"

I want to replace the periods with a space, if possible.
And if there is a better way to make this script, that would be better
to. Perhaps, better looking output? ;) Is there a way to just get the IP
address without the other IP info?

TIA,
Jim
 
Jim in Arizona said:
How do I put in a line break, like in the following script:

ipconfig > "%userprofile%\Desktop\COMPUTER INFO.txt"
echo . >> "%userprofile%\Desktop\COMPUTER INFO.txt"
echo . >> "%userprofile%\Desktop\COMPUTER INFO.txt"
echo ============================================================== >>
"%userprofile%\Desktop\COMPUTER INFO.txt"
echo . >> "%userprofile%\Desktop\COMPUTER INFO.txt"
echo . >> "%userprofile%\Desktop\COMPUTER INFO.txt"
echo COMPUTER NAME >> "%userprofile%\Desktop\COMPUTER INFO.txt"
echo -------------------- >> "%userprofile%\Desktop\COMPUTER INFO.txt"
hostname >> "%userprofile%\Desktop\COMPUTER INFO.txt"

I want to replace the periods with a space, if possible.
And if there is a better way to make this script, that would be better
to. Perhaps, better looking output? ;) Is there a way to just get the IP
address without the other IP info?

As Phil has already mentioned, you can get echo to emit a blank or null line
with either of the following:

echo.
echo/

It can be a good idea to ALWAYS use one or the other, even when the output
is non-null. For example, this code:

set output=
echo %output%

will display "ECHO is ON" instead of a blank line, whereas

echo.%output%
echo/%output%

will emit two blank lines.

I used to use "echo.", but have switched to "echo/" as a result of the
possibility of this kind of problem:

set output=exe
echo.%output%

The above will not output a line containing "exe", but will attempt to run
an executable called echo.exe. On the other hand, "echo/%output%" will
output the value of the output variable, even if it is "exe".

A further suggestion that I find easier to read (and to type) is to place
the redirection before the command, i.e.:
"%userprofile%\Desktop\COMPUTER INFO.txt" ipconfig

This also makes it easier to spot spelling errors in the output filename.

Whenever you want to redirect ALL of the output of a chunk of code, however,
there is an even simpler method that involves using parenthesis to create a
compound statement and simply redirecting its output, as in:

(
ipconfig
echo/
echo/
echo ====
echo/
echo/
echo COMPUTER NAME
echo --------------------
hostname
)>"%userprofile%\Desktop\COMPUTER INFO.txt"

The advantages of this include:

- the name of the output file is given only once, so it is not possible to
spell it differently for some of the commands.

- the individual commands are shorter, simpler, and easier to read (and to
type).

- if you need to re-order the commands you do not need to remember to
adjust the >'s such that the first one is single and the rest double.


/Al
 
Al Dunbar [MS-MVP] wrote:

Whenever you want to redirect ALL of the output of a chunk of code, however,
there is an even simpler method that involves using parenthesis to create a
compound statement and simply redirecting its output, as in:

(
ipconfig
echo/
echo/
echo ====
echo/
echo/
echo COMPUTER NAME
echo --------------------
hostname
)>"%userprofile%\Desktop\COMPUTER INFO.txt"

The advantages of this include:

- the name of the output file is given only once, so it is not possible to
spell it differently for some of the commands.

- the individual commands are shorter, simpler, and easier to read (and to
type).

- if you need to re-order the commands you do not need to remember to
adjust the >'s such that the first one is single and the rest double.


/Al

That's a *great* reminder, Al! These are advantages indeed! I shall
try to remember to start using this from now on.
 
Back
Top