Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: need help, should be simple... something like tokens  (Read 9328 times)

0 Members and 1 Guest are viewing this topic.

Redd4

    Topic Starter


    Rookie

    • Experience: Familiar
    • OS: Windows XP
    need help, should be simple... something like tokens
    « on: January 28, 2013, 05:34:25 AM »
    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 .

    foxidrive



      Specialist
    • Thanked: 268
    • Experience: Experienced
    • OS: Windows 8
    Re: need help, should be simple... something like tokens
    « Reply #1 on: January 28, 2013, 07:33:24 AM »
    Shows us the string that is returned and it should be an easy fix.   Not knowing the whole string makes it a guessing game.

    Redd4

      Topic Starter


      Rookie

      • Experience: Familiar
      • OS: Windows XP
      Re: need help, should be simple... something like tokens
      « Reply #2 on: January 28, 2013, 08:09:24 AM »
      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\123451234567

      Redd4

        Topic Starter


        Rookie

        • Experience: Familiar
        • OS: Windows XP
        Re: need help, should be simple... something like tokens
        « Reply #3 on: January 28, 2013, 08:10:29 AM »
        I need to somehow grab one of those uuids and add it to the end of my next command

        foxidrive



          Specialist
        • Thanked: 268
        • Experience: Experienced
        • OS: Windows 8
        Re: need help, should be simple... something like tokens
        « Reply #4 on: January 28, 2013, 08:14:39 AM »
        There 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:

        Redd4

          Topic Starter


          Rookie

          • Experience: Familiar
          • OS: Windows XP
          Re: need help, should be simple... something like tokens
          « Reply #5 on: January 28, 2013, 08:20:30 AM »
          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.

          Redd4

            Topic Starter


            Rookie

            • Experience: Familiar
            • OS: Windows XP
            Re: need help, should be simple... something like tokens
            « Reply #6 on: January 28, 2013, 08:21:18 AM »
            edit noted

            Redd4

              Topic Starter


              Rookie

              • Experience: Familiar
              • OS: Windows XP
              Re: need help, should be simple... something like tokens
              « Reply #7 on: January 28, 2013, 09:22:33 AM »

              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 .

              Lemonilla



                Apprentice

              • "Too sweet"
              • Thanked: 70
              • Computer: Specs
              • Experience: Experienced
              • OS: Windows 7
              Re: need help, should be simple... something like tokens
              « Reply #8 on: January 28, 2013, 09:49:57 AM »
              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.
              Quote from: patio
              God Bless the DOS Helpers...
              Quote
              If it compiles, send the files.

              Redd4

                Topic Starter


                Rookie

                • Experience: Familiar
                • OS: Windows XP
                Re: need help, should be simple... something like tokens
                « Reply #9 on: January 28, 2013, 10:29:20 AM »
                thanks Lemonilla. I just clicked how to read the help results, cheers

                foxidrive



                  Specialist
                • Thanked: 268
                • Experience: Experienced
                • OS: Windows 8
                Re: need help, should be simple... something like tokens
                « Reply #10 on: January 28, 2013, 03:43:31 PM »

                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.

                Redd4

                  Topic Starter


                  Rookie

                  • Experience: Familiar
                  • OS: Windows XP
                  Re: need help, should be simple... something like tokens
                  « Reply #11 on: January 29, 2013, 03:38:04 AM »
                  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

                  Redd4

                    Topic Starter


                    Rookie

                    • Experience: Familiar
                    • OS: Windows XP
                    Re: need help, should be simple... something like tokens
                    « Reply #12 on: January 29, 2013, 07:20:28 AM »
                    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.

                    Lemonilla



                      Apprentice

                    • "Too sweet"
                    • Thanked: 70
                    • Computer: Specs
                    • Experience: Experienced
                    • OS: Windows 7
                    Re: need help, should be simple... something like tokens
                    « Reply #13 on: January 29, 2013, 01:27:23 PM »
                    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

                    Quote from: patio
                    God Bless the DOS Helpers...
                    Quote
                    If it compiles, send the files.

                    Redd4

                      Topic Starter


                      Rookie

                      • Experience: Familiar
                      • OS: Windows XP
                      Re: need help, should be simple... something like tokens
                      « Reply #14 on: January 30, 2013, 02:08:55 AM »
                      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