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

Author Topic: Help needed for a batch file to extract data from text files  (Read 5869 times)

0 Members and 1 Guest are viewing this topic.

wharfbanger

    Topic Starter


    Newbie

    • Experience: Experienced
    • OS: Windows 7
    Help needed for a batch file to extract data from text files
    « on: January 07, 2015, 02:08:42 AM »
    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=LEFT

    foxidrive



      Specialist
    • Thanked: 268
    • Experience: Experienced
    • OS: Windows 8
    Re: Help needed for a batch file to extract data from text files
    « Reply #1 on: January 07, 2015, 04:06:16 AM »
    This 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"