1.

Solve : need help, should be simple... something like tokens?

Answer»

I need some help with a script I'm trying to write please. Ive been at this for days and Im not really getting anywhere, although I am getting to know cmd a lot better.

ill try describe what my script has to do, i cant write the commands out on the net im afraid

-------------------------------------------------------------------------------------------------------------------

The script passes the command line a command. CMD returns 4 lines of code. on the third line there is the UUID of the last software build. its not a hardware uuid.

I need to get my script to copy this UUID and APPEND it onto the end of the next command my script passes, in order to proceed with the script.


-------------------------------------------------------------------------------------------------------------------

I'm new to this, I have been watching tutorials, and saw that tokens do something similar, so i tried to write a script using them. it doesnt work though, it keeps telling me it needs a unique key, in other words it doesnt have the uuid


------------------------------------------------------------------------------------------------------------


for /F "tokens=16" %%i in ('the command needed to return the lines of code') do set barney=%%i

something UNREGISTER -view -uuid %barney%



------------------------------------------------------------------------------------------------------------


alas this is not working. can ANYONE point me in the right direction please? im thinking something like substring or equivalent, but the uuid starts like 120 characters into the returned output, so both tokens ans substring seem wrong

can anyone help please?

kind regards,
redd .SHOWS us the string that is returned and it should be an easy fix. Not knowing the whole string makes it a guessing game.cheers for the reply, I appreciate it


I cant show you the returned output unfortunately. I can show you an edited version with the correct amount of characters but not the words.
this is because I'm in work, I'm an intern.

Tag: 12345.A.B
Global path: \\1234.1234512345678.com\CC\12345.A.B
Server host: snap.1234512345678.com
Region: windows
Active: NO
View tag uuid:d0a32387.0e874aae.85aa.86:bd:6a:ac:d3:ed
View on host: snap.1234512345678.com
View server access path: C:\CC\12345.A.B
View uuid: d0a32387.0e874aae.85aa.86:bd:6a:ac:d3:ed
View attributes: snapshot
View owner: 123456789\123451234567I need to somehow grab one of those uuids and add it to the end of my next commandThere are more than 4 lines there

This should work (untested) after you replace command1 with the command that returns those lines, and command 2 is your next command to use the uuid. ATM it will just echo the text to the console.


for /f "tokens=2,* delims=: " %%a in (' command1 ^|find /i "uuid:" ') do set "var=%%b"
echo command2 %var%

Note that I edited the above:thanks! Ill try it out and replort back. I think it may be tomorrow before I know, at the more theres a cleanup being peformed, so theres no UUID's to speak of.

I will report back though, once again, many thanks.edit noted
okay, im just analysing what you did, and its pretty sweet. i have been trying to find a way to do this for a week now, so its nice seeing a way forward. may i ask you a few questions about the bits I dont understand please?


so far as I can make out, you searched the output for the string "uuid" and stored it, and the token next to it, as A and B.

I'm guessing the * next to tokens stores everything that was returned?

you then piped it to "Find" to search for the string "uuid"

may I ask what the /i does?

regards,
redd .
Quote from: cmd.exe

C:\Users\Lemonilla\Documents\bat>find /?
FIND [/V] [/C] [/N] [/I] [/OFF[LINE]] "string" [[drive:][path]filename[ ...]]

/V Displays all lines NOT containing the specified string.
/C Displays only the count of lines containing the string.
/N Displays line numbers with the displayed lines.
/I Ignores the case of characters when searching for the string.
/OFF[LINE] Do not SKIP files with offline attribute set.
"string" Specifies the text string to find.
[drive:][path]filename
Specifies a file or files to search.

If a path is not specified, FIND searches the text typed at the prompt
or piped from another command.
thanks Lemonilla. I just clicked how to read the help results, cheersQuote from: foxidrive on January 28, 2013, 08:14:39 AM

for /f "tokens=2,* delims=: " %%a in (' command1 ^|find /i "uuid:" ') do set "var=%%b"

It takes the lines that command1 generates and uses FIND to separate the ones that have uuid: in them.

The FOR then splits those lines up into 'words' by removing : and spaces (as delimiters)
2,* takes the 2nd word and then everything after the second word, and sets var to everything after the second word by incrementing %%a to %%b

In your example it will do this twice, once for each occurrence of uuid: and will remember the last one.hey all. Thanks for explaining that Foxidrive. It seems this site is one of the only resources for learning msdos on the net. I found Dilberts tutorial and am having a good look through it.
Theres a guy on youtube also, starkIndustries, hes very good, but, the tutorials cut off at a certain point. - a certain point before the level of foxidrive's command lol, it never gets that advanced.

anywho, I tried the command this morning, and got a "The syntax of the command is incorrect." reply

so i tried with with a SYSTEMINFO command in the parenthesis, and a different string to find, but the same error came back.

it seems theres something slightly awry with the first line okay, if I take out the * and replace it with 3, -

for /f "tokens=2,3" %a in (' SYSTEMINFO ^|find /i "broadcom" ') do set "var=%b"
echo I like cats and %var%


It works! woohoo! i get this


C:\Windows\System32>echo I like cats and %var%
I like cats and NetXtreme


however, it requires that i hit enter after

C:\Windows\System32>echo I like cats and %var%

in order to get the next line, "I like cats and NetXtreme" which is not ideal. brilliant though, love it.The extra enter may be due to running it from command line, when I run it in a batch file, It doesn't pause (until my 'pause>nul').

Code: [Select]@echo off
for /f "tokens=2,3" %%A in (' systeminfo ^| find /i "broadcom" ') do set "var=%%B"
echo I like cats and %var%
pause>nul

Code: [Select]
C:\Users\Lemonilla>cd ..\..

C:\>test.bat
I like cats and 802.11n

your right, I just had a go there and it ran through without pausing.

If i may id like to as another question. the batch file im trying to create has in it three tasks. first is the one above, and the next are two delete commands.
the scripts is one of many executed my anthill pro as part of a nightly software build. so, i have to add error handling, im a little bit confused about it.. so far my file goes like this, using the example above

--------------------------------------------------------------------------------------------------

:: step 1

for /f "tokens=2,3" %%a in (' SYSTEMINFO ^|find /i "broadcom" ') do set "var=%%b"

if there are no tokens -

IF ERRORLEVEL 1 (
goto builderror
)

echo I like cats and %var%


:: below are to delete the directories
::----------------------------------------------
:: step 2

RD /S /q C:\CA\repositorydriver\directoryA

IF ERRORLEVEL 1 (
goto builderror
)

:: step 3

RD /S /q C:\CA\repositorydriver\directoryB

IF ERRORLEVEL 1 (
goto builderror
)


:builderror
echo *** An error has occured executing clearRegistry.bat


:exit


Discussion

No Comment Found