Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.
c:\test> gawk "{a[$1]=$2}END{for(i in a)print i,a[i]}" file >logfile.txtWST123 11:27WST567 07:27WST789 12:27WST456 03:27
@echo offif exist *.pqr del *.pqr for /f "tokens=1,2 delims= " %%A in (ABC.txt) do echo %%B>%%A.pqrfor /f "delims=" %%B in ('dir /b *.pqr') do ( for /f "delims=" %%C in ('type %%B') do echo %%~nB %%C>>logfile.txt ) del *.pqr
WST456 03:27WST567 07:27WST789 12:27WST123 11:27
@echo offREM The extension .pqr is one I chose at randomREM it can be any extension which is not found in the folderREM delete any files with that extensionif exist *.pqr del *.pqr REM for each line in ABC.txt in turn,REM split the line into 2 tokens %%A and %%BREM %%A is the computer name %%B is the timeREM you create a file: REM whose name is the the computer nameREM whose contents is the timeREM Use the > redirection operator so thatREM each new file overwrites the previous file with that nameREM after this loop you have one .pqr file for each computerREM containing the last time entry for that computerREM for /f "tokens=1,2 delims= " %%A in (ABC.txt) do echo %%B>%%A.pqrREM Now for each file with the extension .pqrREM put the filename into %%Bfor /f "delims=" %%B in ('dir /b *.pqr') do ( REM Echo the name part of the filename and the contents into logfile.txt for /f "delims=" %%C in ('type %%B') do echo %%~nB %%C>>logfile.txt ) REM remove all the .pqr files del *.pqr
if you are so clever, Billrich, explain to Yogesh123 what the code that I posted does, instead of wasting everybody's time with your childish nonsense, which actually is nonsense because it does not mean anything. I supplied code which provided what the OP asked for. As so often happens, you did not.
C:\batextra>type vosloop.batCode: [Select]@echo offfor /f "tokens=1,2,3 delims= " %%a in (abc2.txt) do (echo %%a %%b %%c)type abc2.txt >> voslog.logOUTPUT:C:\batextra> vosloop.batWST123 01:27 pmWST456 02:27 pmWST789 11:27 pmWST123 05:27 pmWST567 12:27 pmWST123 08:27 pmWST567 07:27 pmWST456 03:27 pmWST123 11:27 pmWST789 12:27 pmLog:C:\batextra>type voslog.logWST123 01:27 pmWST456 02:27 pmWST789 11:27 pmWST123 05:27 pmWST567 12:27 pmWST123 08:27 pmWST567 07:27 pmWST456 03:27 pmWST123 11:27 pmWST789 12:27 pmC:\batextra>
@echo offfor /f "tokens=1,2,3 delims= " %%a in (abc2.txt) do (echo %%a %%b %%c)type abc2.txt >> voslog.log
Dear Salmon Trout,Thanx a lot,This thing is really working great,but how does it works exactly?what is *.pqr & 'type %%B' & %%~nB
for /f "tokens=1,2 delims= " %%A in (ABC.txt) do echo %%B>%%A.pqr
if you can download and use gawk for windows(see my sig)Code: [Select]c:\test> gawk "{a[$1]=$2}END{for(i in a)print i,a[i]}" file >logfile.txtWST123 11:27WST567 07:27WST789 12:27WST456 03:27next time, try writing the code yourself first.
If your ABC.txt has many entries, this will be a slow batch process due to i/o. Its probably more efficient to use memory (delayed expansion??? ) than i/o.
S:\Test>(More? echo %date% %time%More? ltime3.batMore? echo %date% %time%More? )14/11/2009 15:57:24.0614/11/2009 15:57:32.41
Casper,Casper gave the same answer as Billrich did. And now Casper questions Billrich's answer?This a Board for Children who fake their answers?
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.batMore? echo %date% %time%More? )14/11/2009 15:57:24.0614/11/2009 15:57:32.41
What he's doing is pure trollery. Needs banning.
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.
When one cannot see their own weaknesses, they do not know whereupon to build strength.
Again no one reading this thread knows what Salmon Trout is taking about.
@echo offfor /f "tokens=1,2,3 delims= " %%A in (ABC.txt) do call set lastentry_%%A=%%B_%%Cfor /f "tokens=1,2,3,4 delims=_=" %%A in ('set ^| find "lastentry"') do echo %%B %%C %%D >> logfile.txt
WST123 11:27 pmWST456 03:27 pmWST567 07:27 pmWST789 12:27 pm
Got it! I knew there must be a way that does not involve files.