how to get some text informations from a nontext file using batch commands in Windows? -


guys. i'm trying file version inside nontext files. in each of them (approximately @ beginning) there few text lines containing informations file. example:

[some nontext data (very few)] version: 455467 build date: 23.11.2010 ..... [rest of nontext data] 

if want i'll try make such file can't show original files (my company won't allow it). sorry...

i tried code:

@echo off /f "tokens=1,2" %%a in (file.dat) if %%a==version: (set version=%%b goto found) echo not found goto end :found echo found: %version% :end pause 

but works if "file.dat" text file, if not "not found". if replace file.dat 'type file.dat' not return (processor usage 100%). if replace file.dat 'find /i "version:" file.dat' works, it's very, slow (minutes). since have process many files , have little time can't use it. works lot faster if enter each file manually viewer , copy version number; point want cmd...

oh, , can't install other programs on computer i'm working....

the os windows xp x86.

please me. thank you.

best regards, cosmin

later edit: have "build" test file can see , test: http://www.mediafire.com/download.php?r0x5702lkv14jro it's small (real files have dozens, hundreds of mb).

later later edit: test file useful test if code finds number but, been small, doesn't give idea how time needed real data file. can this: measure time in test file scanned , multiply "100 mb / 2088 bytes" = 50 219. example works "find". "type" slower (i think it's exponentially, not liniar).

i used simplified version of jeb's fc read binary technique read first 1024 bytes of dat file. ( converting binary file hex representation using batch file ) preserve printable ascii characters , <lf>, rest throw away. used compare file containing 1024 <backspace> characters don't have worry gaps in fc output.

i use map developed hexdump.bat routine ( http://www.dostips.com/forum/viewtopic.php?p=7038 ) convert hex representation ascii characters.

then left straight forward string manipulation parse version. <lf>version:, strip leading spaces, , take printable characters until next <lf> version value.

this solution assumes version lies within first 1024 characters. extended support first 8k increasing size of compare file.

the solution seems plenty fast, , size of dat file should have no impact on performance.

@echo off setlocal enabledelayedexpansion  :: build binary file containing 1024 <backspace> characters set comparefile="bs1024.dat" if not exist %comparefile% (   /f "tokens=1 delims=# " %%a in ('"prompt #$h#$e# & echo on & %%b in (1) rem"') (     <nul set/p"=%%a" >%comparefile%   )   /l %%n in (1 1 10) type %comparefile% >>%comparefile% )  :: create variable containing <linefeed> character (0x0a) set lf=^   :: above 2 blank lines critical - not remove.  :: grab first 1024 bytes, preserving printable ascii characters , <linefeed> set map= ^^^!^"#$%%^&'^(^)*+,-./0123456789:;^<=^>?@abcdefghijklmnopqrstuvwxyz[\]^^^^_`abcdefghijklmnopqrstuvwxyz{^|}~ set datfile="test.dat" set "dat=" /f "eol=f usebackq tokens=2 skip=1 delims=:[] " %%a in (`fc /b %datfile% %comparefile%`) (   if "%%a"=="0a" (set "dat=!dat!!lf!") else (     set /a "n=0x%%a-32"     if !n! geq 0 if !n! leq 94 %%n in (!n!) set "dat=!dat!!map:~%%n,1!"   ) )  :: find version line , value set "version=" %%c in ("!lf!") set "dat2=!dat:*%%~cversion:=!" if "!dat2!" neq "!dat!" (   /f "tokens=* eol= delims= " %%a in ("!dat2!") (     set "version=%%a"     goto :done   ) ) :done set version 

Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -