1.

Solve : Help needed for a batch file to extract data from text files?

Answer»

Hi,

I have over 1000 TEXT files.  The files are located in about 40 subdirectories, all within a single parent directory.  All files are in the same format (example file below).  I would LIKE to be able to extract data to a single output txt file as follows:

2014-02-26 21.51.53.000.TIF, -38.72672, 176.05866, 1413.2

Note the first output field is the input filename, but with the suffix changed to .tif. 

I am hoping SOMEONE can help me WRITE a batch file that would do this.  I have no experience writing batch files.

Regards,
Mark

EXAMPLE FILE
File name:  2014-02-26 21.51.53.000.txt

latitude=-38.72672
longitude=176.05866
height=1413.2
nSatellites=9
GPSHeading=146.1105594523
speed=64.2541111111
yaw=146.1105594523
pitch=-1
roll=-1
nFlightLine=1
nImageNumber=1
AVIATRIX_VERSION=5th DEC 2013
LUTFile=5
computerTimeStamp=201402262153015648
imageFormat=TIFF
imageWidth=640
imageHeight=480
imagePixelDepth=0
imageMode=0
minPixelValue=12716
maxPixelValue=12865
cameraModelName=FLIR A615
selectedCamera=A615
cameraDate=26/02/2014 9:53:01 AM
cameraMS=476
temperatureUnits=0
focusMotorState=stop
focusAbsolutePosition=5071
currentType=15
currentLens=
deviceType=8
commPort=0
zoomFactor=1
frameRate=25
//////////////////////////////////////////////////
/////////////// DEBUG STUFF BELOW ////////////////
//////////////////////////////////////////////////
validGPSSignal=True
outputPath=C:\TIR data\wk-th\FlightPlanner\wk-th  2014-02-13\Aviatrix\2014-02-26 21.25.10
bConnected=True
MD_filename=C:\TIR data\wk-th\FlightPlanner\wk-th  2014-02-13\Aviatrix\2014-02-26 21.25.10\METADATA\RUN1\2014-02-26 21.51.53.000.txt
freeRunMode=False
flightLineMode=True
flightPlanFile=wk-th.fpl
freeRunFrequency_at_10Hz=40
cameraName=FLIR A615-25
trackBarOffTrackTolerance=77.5677496332519
distanceToFlightLine=29.9671440045477
sideOfFlightLine=LEFTThis is close:

Code: [Select]echo off
(
for /f "delims=" %%a in ('dir *.txt /a:-d /b /s') do (
 set /p "=%%~na.tif,"<nul
 set "skip="
   for /f "usebackq tokens=1,2 delims==" %%b in ("%%a") do (
      if not defined skip set /p "=%%c,"<nul
      if "%%b"=="height" set skip=1
   )
 echo(
 )
)>"file.log"



Discussion

No Comment Found