Home / Microsoft / Microsoft DOS / Batch - How to Read text file variables in a loop
0 Members and 1 Guest are viewing this topic. « previous next »
Pages: 1 [2]  All - (Bottom) Print
Author Topic: Batch - How to Read text file variables in a loop  (Read 1355 times)
Salmon Trout
Prodigy



Thanked: 501
Posts: 7,364

Computer: Specs
Experience: Guru
OS: Linux variant

1
« Reply #15 on: November 14, 2009, 09:05:12 AM »

What he's doing is pure trollery. Needs banning.
IP logged

gh0std0g74
Apprentice



Thanked: 37
Posts: 590


« 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.
IP logged

billrich
Guest
« 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 » IP logged
BC_Programmer
Mastermind


Thanked: 682
Posts: 15,624

Computer: Specs
Experience: Beginner
OS: Windows 7


Pinkie Pie is best pony

BC-Programming.com 1 1
« 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.
IP logged

Salmon Trout
Prodigy



Thanked: 501
Posts: 7,364

Computer: Specs
Experience: Guru
OS: Linux variant

1
« 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.
IP logged

Salmon Trout
Prodigy



Thanked: 501
Posts: 7,364

Computer: Specs
Experience: Guru
OS: Linux variant

1
« 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.
IP logged

gh0std0g74
Apprentice



Thanked: 37
Posts: 590


« 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.
IP logged

Salmon Trout
Prodigy



Thanked: 501
Posts: 7,364

Computer: Specs
Experience: Guru
OS: Linux variant

1
« 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 » IP logged

gh0std0g74
Apprentice



Thanked: 37
Posts: 590


« 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.
IP logged

Pages: 1 [2]  All - (Top) Print 
Home / Microsoft / Microsoft DOS / Batch - How to Read text file variables in a loop « previous next »
 


Login with username, password and session length

Old Forum Search | Forum Rules
Copyright © 2010 Computer Hope ® All rights reserved.
Powered by SMF 2.0 RC3 | SMF © 2006–2010, Simple Machines LLC
Page created in 0.2 seconds with 20 queries.