#1 15 Aug 2006 05:28

NoobTube
Member
Registered: 15 Aug 2006
Posts: 1

FOR /F usage tricks?

@ECHO off
@ECHO.
@ECHO PLEASE ENTER THE FULL NAME OF THIS COMPUTERS MAIN USER
@ECHO.
@SET /P OWNERNAME=
@FOR /F "tokens=1 delims=," %%G IN ('"%SYSTEMROOT%\system32\getmac.exe" /FO CSV /NH') DO echo %%G >> .\full.txt
@ECHO %OWNERNAME%,%COMPUTERNAME%, >> .\full.txt

Current output
"72-19-E4-AA-AA-AA"
"00-11-D8-AA-AA-AA"
Owner Name,Computername,

Desired output
Owner Name,Computername,"00-11-D8-4A-07-5C","72-19-E4-51-37-DD"

Please forgive my stupid question. I know the answer is dirt simple, I just don't know it.

Offline

#2 15 Aug 2006 16:55

//[T.0.P]//
Member
Registered: 12 Aug 2006
Posts: 50

Re: FOR /F usage tricks?

Here is one way of solving your problem, although it will require an extra sub-routine.

FOR /F "tokens=1 delims," %%g in ("%SYSTEMROOT%\system32\getmac.exe" /FO CSV /NH') DO call :ADD_TO_FILE %%g
echo. %OWNERNAME%,%COMPUTERNAME%,%_fileline%>>.\full.txt

:ADD_TO_FILE
if DEFINED _fileline set _fileline=%_fileline%%*
if NOT DEFINED _fileline set _fileline=%*,
goto :eof

Offline

#3 29 Dec 2006 17:10

bluesxman
Member
From: UK
Registered: 29 Dec 2006
Posts: 1,083

Re: FOR /F usage tricks?

Yeah I'm a tad late, but this is how I would do it:

@echo off
setlocal enabledelayedexpansion

echo:PLEASE ENTER THE FULL NAME OF THIS COMPUTERS MAIN USER
set /P OWNERNAME=^>^> 

set ownername=%ownername%,%computername%

for /F "tokens=1 delims=," %%G IN ('"%SYSTEMROOT%\system32\getmac.exe" /FO CSV /NH') DO set ownername=!ownername!,%%G

echo:%OWNERNAME%>> .\full.txt

- OR -

If you don't want to use delayed expansion for some reason:

@echo off

echo PLEASE ENTER THE FULL NAME OF THIS COMPUTERS MAIN USER
set /P OWNERNAME=^>^> 

set ownername=%ownername%,%computername%

for /F "tokens=1 delims=," %%G IN ('"%SYSTEMROOT%\system32\getmac.exe" /FO CSV /NH') DO call :addvalue %%G

echo %OWNERNAME%>> .\full.txt

goto :EOF

:addvalue

set ownername=%ownername%,%1

goto :EOF

BTW: All your @ symbols (excluding the one on the "@echo off" line) are redundant.


cmd | *sh | Ruby | Chef

Offline

Board footer

Powered by FluxBB