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

Author Topic: Set Var=?  (Read 6354 times)

0 Members and 1 Guest are viewing this topic.

nothlit

    Topic Starter


    Intermediate

    Thanked: 2
    Set Var=?
    « on: April 30, 2008, 04:12:27 PM »
    Code: [Select]
    *NAME         RESET         WARN             MAX      INIT       EXPRESSION             INCREMENT
    PRIMESEQ 00###00000 00###30000 00###90000   0  SEQUENCE+INCREMENT            5

    What I am after here, above I have a *cfg file that is stored locally on many client machines, I am wanting to write a bat file that will edit this file and figured out what the reset value is or more importantly the 3 digits that are marked as ### in other words I want to create a Variable that will set to %VAR:~94,3% based on the text in the file, but I have no clue how to pull out the needed information, I could try a find command, but am still learning as I go and any help would be greatly appreciated. 

    The reason for this rewrite, many of the customers have an old configuration where they run out of numbers and don't reset on time due to a small number between the warn and max, when I rewrite the *cfg file for example say the reset is already 0011100000 the warm and max would be 112 and would fix some client issues. Thanks for the help.
    « Last Edit: May 07, 2008, 12:36:48 PM by nothlit »

    nothlit

      Topic Starter


      Intermediate

      Thanked: 2
      Re: Set Var=?
      « Reply #1 on: May 07, 2008, 12:38:15 PM »
      Anyone have an idea that would point me in the right direction? :)

      Dias de verano

      • Guest
      Re: Set Var=?
      « Reply #2 on: May 07, 2008, 02:01:15 PM »
      the 3 digits that are marked as ### in other words I want to create a Variable that will set to %VAR:~94,3% based on the text in the file

      I see 9 digits marked as ###.

      nothlit

        Topic Starter


        Intermediate

        Thanked: 2
        Re: Set Var=?
        « Reply #3 on: May 08, 2008, 01:31:45 PM »
        More details. :)

        In this file, I am trying to pull the reset value, for example lets say the reset value is 0012300000, I would want to pull out '123' and have that be my variable, then for the warn I would want to add +1 so the new value for the variable would be 124 and the max would also be 124, sorry for the confusion with the extra ### symbols.

        Dias de verano

        • Guest
        Re: Set Var=?
        « Reply #4 on: May 08, 2008, 01:42:31 PM »
        Are the 3 digits always the ones specified by %VAR:~94,3%, that is, are they the 95rd, 96th and 97th characters in the string (in which the first chaarcter is character 0)?

        In that case you can use set /a (a is for arithmetic) to extract them as a numerical variable and increment by 1 and test if the limit has been reached.



        nothlit

          Topic Starter


          Intermediate

          Thanked: 2
          Re: Set Var=?
          « Reply #5 on: May 12, 2008, 07:25:24 AM »
          The first char should always be '00' then the number I need to pull, but the spacing could be off in the file so the ~94 could change.

          Dias de verano

          • Guest
          Re: Set Var=?
          « Reply #6 on: May 12, 2008, 10:39:43 AM »
          Are they always like this...

          One line with 14 "words" separated by spaces?

          *NAME         RESET         WARN             MAX      INIT       EXPRESSION             INCREMENT PRIMESEQ   00###00000 00###30000 00###90000   0  SEQUENCE+INCREMENT            5

          nothlit

            Topic Starter


            Intermediate

            Thanked: 2
            Re: Set Var=?
            « Reply #7 on: May 12, 2008, 01:06:24 PM »
            Correct

            Dias de verano

            • Guest
            Re: Set Var=?
            « Reply #8 on: May 12, 2008, 01:44:19 PM »
            So, it's all on one line & you want the 3 red digits in the blue section?

            And the numbers might change but the structure does not?

            *NAME         RESET         WARN             MAX      INIT       EXPRESSION             INCREMENT PRIMESEQ   00###00000 00###30000 00###90000   0  SEQUENCE+INCREMENT            5


            nothlit

              Topic Starter


              Intermediate

              Thanked: 2
              Re: Set Var=?
              « Reply #9 on: May 12, 2008, 02:18:39 PM »
              I might have misunderstood. It is probably two lines, meaning that the 'Enter' Key was probably pushed, but that would be a correct statement in saying the structure doesn't change, but the numbers do.

              Dias de verano

              • Guest
              Re: Set Var=?
              « Reply #10 on: May 12, 2008, 03:02:59 PM »
              I might have misunderstood. It is probably two lines, meaning that the 'Enter' Key was probably pushed, but that would be a correct statement in saying the structure doesn't change, but the numbers do.

              "probably" won't hack it

              nothlit

                Topic Starter


                Intermediate

                Thanked: 2
                Re: Set Var=?
                « Reply #11 on: May 12, 2008, 06:41:02 PM »
                Ok I double checked it is two lines

                Dias de verano

                • Guest
                Re: Set Var=?
                « Reply #12 on: May 13, 2008, 12:07:23 AM »
                Ok I double checked it is two lines


                How do they split?
                 

                nothlit

                  Topic Starter


                  Intermediate

                  Thanked: 2
                  Re: Set Var=?
                  « Reply #13 on: May 13, 2008, 07:35:48 AM »
                  Code: [Select]
                  *NAME         RESET         WARN             MAX      INIT       EXPRESSION             INCREMENT
                  PRIMESEQ 00###00000 00###30000 00###90000   0  SEQUENCE+INCREMENT            5

                  They split after increment, the new lines starts with PRIMESEQ

                  Dias de verano

                  • Guest
                  Re: Set Var=?
                  « Reply #14 on: May 13, 2008, 12:04:54 PM »
                  This is test.cfg

                  Quote
                  *NAME         RESET         WARN             MAX      INIT       EXPRESSION             INCREMENT
                  PRIMESEQ 0012300000 00###30000 00###90000   0  SEQUENCE+INCREMENT            5

                  This is test.bat

                  Quote
                  @echo off

                  set filename=test.cfg

                  echo demo: show file
                  type %filename%
                  echo.
                  echo demo: show line containing PRIMESEQ
                  type %filename% | find "PRIMESEQ"
                  echo.

                  REM This does the work
                  REM get 2nd space-delimited token from line
                  for /f "tokens=1,2 delims= " %%T in ('type %filename% ^| find "PRIMESEQ"') do set string=%%U

                  echo demo: show 2nd token
                  echo %string%

                  REM get the 3 chars starting at offset 2 from start of string (i.e. chars 3, 4 & 5)
                  REM put it into an arithmetic variable
                  set /a number=%string:~2,3%
                  echo.
                  echo demo: show reset number
                  echo %number%

                  This is the output

                  Quote
                  C:\>test.bat
                  demo: show file
                  *NAME         RESET         WARN             MAX      INIT       EXPRESSION             INCREMENT
                  PRIMESEQ 0012300000 00###30000 00###90000   0  SEQUENCE+INCREMENT            5

                  demo: show line containing PRIMESEQ
                  PRIMESEQ 0012300000 00###30000 00###90000   0  SEQUENCE+INCREMENT            5

                  demo: show 2nd token
                  0012300000

                  demo: show reset number
                  123