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

Author Topic: Batch for comparing values  (Read 10578 times)

0 Members and 1 Guest are viewing this topic.

Blisk

    Topic Starter


    Intermediate

    Thanked: 1
    • Experience: Familiar
    • OS: Windows 7
    Batch for comparing values
    « on: April 17, 2014, 01:01:52 AM »
    Hi people. I need some help if someone can help me?
    I have a txt log file from where I need to take a value and compare it with value from another txt file.
    If value from another file is lower than value from first file than it must take an action.

    Belov is a log from first txt file. I need to take out value from last line (avg):140.5Kh/s. In second txt file I write my value, like 100

    Code: [Select]
    [2014-04-17 07:13:00] Accepted 5d447098 Diff 65/32 GPU 0                     
    (5s):140.8K (avg):140.4Kh/s | A:32  R:0  HW:0  U:4.9/m  WU:156.9/m          (5s):140.8K (avg):140.4Kh/s | A:32  R:0  HW:0  U:4.8/m  WU:154.9/m           [2014-04-17 07:13:12] Accepted e7790f5c Diff 42/32 GPU 0                     
    (5s):140.9K (avg):140.4Kh/s | A:33  R:0  HW:0  U:4.9/m  WU:157.7/m           [2014-04-17 07:13:15] Accepted 79988ae3 Diff 45/32 GPU 0                     
     [2014-04-17 07:13:16] Accepted d68372c1 Diff 74/32 GPU 0                     
    (5s):140.9K (avg):140.5Kh/s | A:35  R:0  HW:0  U:5.2/m  WU:165.2/m         
    (5s):140.9K (avg):140.5Kh/s | A:35  R:0  HW:0  U:5.1/m  WU:163.2/m          (5s):141.0K (avg):140.5Kh/s | A:35  R:0  HW:0  U:5.0/m  WU:161.3/m     

    foxidrive



      Specialist
    • Thanked: 268
    • Experience: Experienced
    • OS: Windows 8
    Re: Batch for comparing values
    « Reply #1 on: April 17, 2014, 01:42:52 AM »
    Please attach a sample of your text file to a post, and describe the filenames and what you need to do. 

    The file data you pasted in looks like it was corrupted.

    Blisk

      Topic Starter


      Intermediate

      Thanked: 1
      • Experience: Familiar
      • OS: Windows 7
      Re: Batch for comparing values
      « Reply #2 on: April 17, 2014, 01:53:51 AM »
      No it is not corrupted it is that way.


      [recovering disk space, attachment deleted by admin]

      foxidrive



        Specialist
      • Thanked: 268
      • Experience: Experienced
      • OS: Windows 8
      Re: Batch for comparing values
      « Reply #3 on: April 17, 2014, 02:17:36 AM »
      Are you sure? The mylog.txt is nothing like what you posted above.

      If the figure following (avg) on the last line is what you need to compare, does it have to take the figures after the decimal point into account
      or can it just compare the figures to the left of the decimal point?

      Blisk

        Topic Starter


        Intermediate

        Thanked: 1
        • Experience: Familiar
        • OS: Windows 7
        Re: Batch for comparing values
        « Reply #4 on: April 17, 2014, 02:29:54 AM »
        Yes I am soure that's the way it is :)
        yes the figure after avg and it is not important which from last line it can be first or last.
        And decimal points also are not important, just the whole number, from (avg):140.5Kh/s just a 140.
        and in next file I will write 100 and if value after avg drops under 100 it will run some application

        foxidrive



          Specialist
        • Thanked: 268
        • Experience: Experienced
        • OS: Windows 8
        Re: Batch for comparing values
        « Reply #5 on: April 17, 2014, 02:42:54 AM »
        compare.txt should only contain a whole number
        and the code will compare the avg figure in the last line of myfile.log with that number.

        If the avg figure is less than the number then it will launch the program listed.

        Code: [Select]
        @echo off
        for /f "usebackq tokens=5  delims=:. " %%a in ("myfile.log") do set avg=%%a
        echo avg="%avg%"
        for /f "usebackq delims=" %%a in ("compare.txt") do if %avg% LSS %%a start "" "c:\program files\folder\myapp.exe"
        pause

        Blisk

          Topic Starter


          Intermediate

          Thanked: 1
          • Experience: Familiar
          • OS: Windows 7
          Re: Batch for comparing values
          « Reply #6 on: April 17, 2014, 03:03:22 AM »
          wau, this is so great it works :)
          it is so simple but so complicated for me because I don 't know how to program.

          Need just one more thing here if you are willing to help.

          one more file where it is written how many time is runned myapp.exe, so everytime is runned it add 1 more if it is runned 1 time than in file is 1 if it is runned 3 times than it is 3 in that file, etc.

          If batch file found out that it is runned for example more than 3 times it runs nextmyapp.exe and not myapp.exe and delete that counter file to zero.

          If nextmyapp.exe is runned more than 3 times it stops to run the whole batch file so it won't happend a loop.


          foxidrive



            Specialist
          • Thanked: 268
          • Experience: Experienced
          • OS: Windows 8
          Re: Batch for comparing values
          « Reply #7 on: April 17, 2014, 05:05:45 AM »
          Need just one more thing here if you are willing to help.

          I'm glad it helps.

          When you ask for free help then you should write the whole task out with as much information that you can provide.

          Asking for more changes once you get some tested code that works means even more work for the people helping you,
          as they have to change the code that is already written and tested, and then test it again.


          Blisk

            Topic Starter


            Intermediate

            Thanked: 1
            • Experience: Familiar
            • OS: Windows 7
            Re: Batch for comparing values
            « Reply #8 on: April 17, 2014, 05:28:12 AM »
            sorry about that you are right.
            But that crossed my mind after I tested this. I didn't think about the whole process. Sorry again

            Blisk

              Topic Starter


              Intermediate

              Thanked: 1
              • Experience: Familiar
              • OS: Windows 7
              Re: Batch for comparing values
              « Reply #9 on: April 17, 2014, 07:55:53 AM »
              Can I still hope for help for that?

              foxidrive



                Specialist
              • Thanked: 268
              • Experience: Experienced
              • OS: Windows 8
              Re: Batch for comparing values
              « Reply #10 on: April 17, 2014, 08:21:23 AM »
              This runs myapp 3 times, then runs mynextapp 3 times, then relaunches the batch file.

              It only launches the apps if the average figure is less than the figure in compare.txt


              Code: [Select]
              @echo off
              :: initialise the app counter files
              if not exist "app1.txt" type nul >"app1.txt"
              if not exist "app2.txt" type nul >"app2.txt"
              if not exist "compare.txt" echo compare.txt is missing&pause&goto :EOF


              :: If app1 has run 3 times then set the variable to app2 (otherwise set it to app1)
              find /c "run" <"app1.txt" | find "3" >nul && (set app=app2) || (set app=app1)

              :: If app2 has run 3 times then remove the counter files and relaunch the batch file
              find /c "run" <"app2.txt" | find "3" >nul && (
                 del "app1.txt" "app2.txt"
                 %0
              )

              :: get the average figure from the last line in the file
              for /f "usebackq tokens=5  delims=:. " %%a in ("myfile.log") do set avg=%%a
              echo avg="%avg%"

              :: get the compare number from the file and if avg is lower,
              :: increment the counter file and run the app - using the app as defined above.
              for /f "usebackq delims=" %%a in ("compare.txt") do if %avg% LSS %%a (
                 if "%app%"=="app1" >>"app1.txt" echo run& start "" "c:\program files\folder\myapp.exe"
                 if "%app%"=="app2" >>"app2.txt" echo run& start "" "c:\program files\folder\mynextapp.exe"
              )

              Blisk

                Topic Starter


                Intermediate

                Thanked: 1
                • Experience: Familiar
                • OS: Windows 7
                Re: Batch for comparing values
                « Reply #11 on: April 17, 2014, 08:29:34 AM »
                Thank you, you really made my day today, finally works all like I wanted.
                Thank you :D

                Blisk

                  Topic Starter


                  Intermediate

                  Thanked: 1
                  • Experience: Familiar
                  • OS: Windows 7
                  Re: Batch for comparing values
                  « Reply #12 on: April 18, 2014, 12:22:11 AM »
                  If I can ask for more help here not to opening new topic?

                  I need one mora batch file for copying the newest file from folder
                  login to folder test\new
                  is it possible to have just a part of path in batch not full path?
                  because I need to make bach fule for each user if it is not possible just part of path.
                  because full path is
                  c:\users\mike\software\screener\database\database2014\office\login

                  c:\users\mike\software\screener\database\database2014\office\test\new

                  foxidrive



                    Specialist
                  • Thanked: 268
                  • Experience: Experienced
                  • OS: Windows 8
                  Re: Batch for comparing values
                  « Reply #13 on: April 18, 2014, 12:52:09 AM »
                  Open a new topic for different questions.  They are free. :)

                  If this is run from the login folder then it will copy the newest file to the new folder shown in your path.

                  Code: [Select]
                  @echo off
                  for /f "delims=" %%a in ('dir /b /od /a-d') do set "lastest_file=%%a"
                  copy "%lastest_file%" "..\test\new"

                  Blisk

                    Topic Starter


                    Intermediate

                    Thanked: 1
                    • Experience: Familiar
                    • OS: Windows 7
                    Re: Batch for comparing values
                    « Reply #14 on: April 18, 2014, 01:06:55 AM »
                    Didn't know about opening new topic because on some forums doesn't like to have every question new topic.

                    This batch not working it copy only itself to folder test\new
                    that also is not ok because there must be only one file

                    I runned this from \login folder where batch file should be