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

Author Topic: Batch - How to Read text file variables in a loop  (Read 7519 times)

0 Members and 1 Guest are viewing this topic.

Salmon Trout

  • Guest
Re: Batch - How to Read text file variables in a loop
« Reply #15 on: November 14, 2009, 09:05:12 AM »
What he's doing is pure trollery. Needs banning.

gh0std0g74



    Apprentice

    Thanked: 37
    Re: Batch - How to Read text file variables in a loop
    « Reply #16 on: November 14, 2009, 09:06:58 AM »
    ABC.txt with 1500 lines (XP SP3, 3. 0 GHZ P4 Prescott, Seagate Free Agent 320GB usb external HDD)

    Code: [Select]
    S:\Test>(
    More? echo %date% %time%
    More? ltime3.bat
    More? echo %date% %time%
    More? )
    14/11/2009 15:57:24.06
    14/11/2009 15:57:32.41
    if you see my gawk code, its makes use of associative arrays.  every time the same entry is encountered, the key is "overwritten" and current value is stored. At the end of file iteration, all it has is just latest entry of each computer name. I think batch can "simulate" this kind of behaviour using delayed expansion. Just feel that its nicer to go through memory than file i/o.

    billrich

    • Guest
    Re: Batch - How to Read text file variables in a loop
    « Reply #17 on: November 14, 2009, 09:12:37 AM »
    What he's doing is pure trollery. Needs banning.


    No, the fishman is the fake and Troll.  

    And now Casper is using vulgar language.

    Again no one  reading this thread knows what Salmon Trout is talking about.

     Yogesh123, the original poster, wrote:

    "How does it works exactly?
    what is *.pqr & 'type %%B' & %%~nB"
    « Last Edit: November 14, 2009, 09:49:35 AM by billrich »

    BC_Programmer


      Mastermind
    • Typing is no substitute for thinking.
    • Thanked: 1140
      • Yes
      • Yes
      • BC-Programming.com
    • Certifications: List
    • Computer: Specs
    • Experience: Beginner
    • OS: Windows 11
    Re: Batch - How to Read text file variables in a loop
    « Reply #18 on: November 14, 2009, 09:25:39 AM »
    The original post seems pretty clear that it indeed the last time entry for each machine name that they wanted It is in bold.

    Of course we could simply print out the very same thing being used as input and call it a day, but that's treading awfully close to what a politician might do (which is quite close to nothing).

    This is all well and good everybody makes mistakes such as this, or misunderstands posts. But to then turn around, and for the sole reason that one was unable to understand the query, accuse others of having multiple accounts to justify in their mind that they were in fact at a disadvantage is nothing short of childish.


    Billrich: your claims that they are the same person are based on a self-deluded fantasy that the provided solution does not meet the request put forth by the OP, when, in fact, it does. Additionally, the very portion that you missed in your solution was bold.

    And lastly, Yes, I know I provided no solution. But is it not true that no solution is better then a wrong one? At least I admit that I did not post a solution, there is no admittance to the clearly obvious fact that you omitted a few key requirements from your original response. This is no problem, a good number of your solutions, while provided in an unorthodox way do solve the OP's problem and they are content. However one cannot say they are perfect all the time, especially when one tries to cover so many threads; as you've said yourself, you are learning, we all are. It never hurts to concede when somebody is better at something, and I have to say from reading many of his posts (I think it's technically in the tens of thousands now, actually) I am not ashamed to say that his abilities with batch(especially regarding the NT extensions), and I'm sure many other things, is far greater then mine; the same goes for ghostdog and his reportoire of script languages; for me to not concede these truths is not a sign of strength in my abilities but rather a folly in that I cannot see my own weaknesses. When one cannot see their own weaknesses, they do not know whereupon to build strength.

    hmm, that got a little weird... anyway, basically, when one finds one solution to be inadequate to the original query, it is not a sign of weakness to say, "hey, I suppose I read wrong or was mistaken", and the same goes for solutions that do work but a better alternative is presented (I believe ghostdog has outscripted me on one or two threads ;), there is no reason the defend a inferior solution unless it has distinct advantages that are applicable to the Original Posters question.

    curses, why must my posts be so long...  

    and lastly, the original posters follow-up question was answered.
    I was trying to dereference Null Pointers before it was cool.

    Salmon Trout

    • Guest
    Re: Batch - How to Read text file variables in a loop
    « Reply #19 on: November 14, 2009, 09:26:12 AM »
    if you see my gawk code, its makes use of associative arrays.  every time the same entry is encountered, the key is "overwritten" and current value is stored. At the end of file iteration, all it has is just latest entry of each computer name. I think batch can "simulate" this kind of behaviour using delayed expansion. Just feel that its nicer to go through memory than file i/o.

    I agree; my code is, I freely admit, nothing more or less than a quick hack. Personally, I would rather tackle the requirement using VBscript.

    Salmon Trout

    • Guest
    Re: Batch - How to Read text file variables in a loop
    « Reply #20 on: November 14, 2009, 09:32:01 AM »
    When one cannot see their own weaknesses, they do not know whereupon to build strength.

    That is an extremely true and profound remark. Further, a person who is (obviously!) painfully aware of their own weaknesses, but out of pig-headedness and vanity refuses to see or address them is in an even more pitiful position.

    gh0std0g74



      Apprentice

      Thanked: 37
      Re: Batch - How to Read text file variables in a loop
      « Reply #21 on: November 14, 2009, 09:36:22 AM »
      Again no one  reading this thread knows what Salmon Trout is taking about.
      i do.

      Salmon Trout

      • Guest
      Re: Batch - How to Read text file variables in a loop
      « Reply #22 on: November 14, 2009, 10:26:58 AM »
      Got it! I knew there must be a way that does not involve files. You have environment space to play with. Remembered about the 'am' & 'pm' part of the time as well. (Why won't people use the 24 hour clock like we do here in Europe? makes things so much simpler.)

      Code: [Select]
      @echo off
      for /f "tokens=1,2,3 delims= " %%A in (ABC.txt) do call set lastentry_%%A=%%B_%%C
      for /f "tokens=1,2,3,4 delims=_=" %%A in ('set ^| find "lastentry"') do echo %%B %%C %%D >> logfile.txt

      logfile.txt (after 1 run) - note that using append >> operator will make logfile.txt grow each time the batch is run

      Code: [Select]
      WST123 11:27 pm
      WST456 03:27 pm
      WST567 07:27 pm
      WST789 12:27 pm
      « Last Edit: November 14, 2009, 11:32:06 AM by Salmon Trout »

      gh0std0g74



        Apprentice

        Thanked: 37
        Re: Batch - How to Read text file variables in a loop
        « Reply #23 on: November 14, 2009, 04:33:06 PM »
        Quote from: Salmon Trout
        Got it! I knew there must be a way that does not involve files.
        congrats. now how about one that uses delayed expansion. would like to see how it can be used to solve this.