Extract Data Without Delimitered Text

September 20, 2010 at 10:45:44
Specs: Windows XP, 2/2Gb
Hi!

I have searched the smilar subjects in this website. But, I couldn't find right answer. I need to extract certain values not having delimitered texts into a new file.

Conditions I have met in the data file is below:
1. There is only one key word available to find the information: BEPS
2. Batch speed is important since the size of file is about 2 or 3 MB.
3. The target value is electric total energy of 3789.2 and total gas energy although it is zero in this case.

Thank you for your help in advance.


910_BL Proposed 1a DOE-2.2-47h1 9/16/2010 14:20:01 BDL RUN 1

REPORT- BEPS Building Energy Performance WEATHER FILE- Miami FL TMY2
---------------------------------------------------------------------------------------------------------------------------------

TASK MISC SPACE SPACE HEAT PUMPS VENT REFRIG HT PUMP DOMEST EXT
LIGHTS LIGHTS EQUIP HEATING COOLING REJECT & AUX FANS DISPLAY SUPPLEM HOT WTR USAGE TOTAL
------- ------- ------- ------- ------- ------- ------- ------- ------- ------- ------- ------- --------

EM1 ELECTRICITY
MBTU 1863.2 0.0 925.9 0.0 345.6 0.0 0.0 327.6 0.0 0.0 63.7 263.2 3789.2

FM1 NATURAL-GAS
MBTU 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0



See More: Extract Data Without Delimitered Text

Report •


#1
September 20, 2010 at 15:07:18
You've got me running for cover on this one. Is this the total content of the input file? Do you need to extract entries in the Header line, if so what are the individual headers?

What do you want your new file to look like?


Report •

#2
September 20, 2010 at 20:31:13
download gawk for windows then do this


C:\test>gawk "$NF~/ELECTRICITY/{getline;te=$NF}$NF~/NATURAL/{getline;tg=$NF}END{print tg, te}" file
0.0 3789.2

GNU win32 packages | Gawk


Report •

#3
September 21, 2010 at 05:40:51
No.The is only a page of the total content which is about 2 thru 4MB text file. The only word that can be used to recognize this page is "BEPS" in upper side and the values will be changed every calculation.

I want to have a new file look below.
ELECTRICITY= 3789.2
NATURAL-GAS= 0.0

Thank you for your help.


Report •

Related Solutions

#4
September 22, 2010 at 14:59:22
Test this, change filenames to paths\filenames to suit your setup..

@echo off>output.txt
cls
setlocal enabledelayedexpansion

set flag1=0&set flag2=!flag1!&set flag3=!flag2!

for /f "tokens=1-14" %%A in (input.txt) do (

    if !flag1! equ 1 if !flag2! equ 1 (
       >>output.txt echo ELECTRICITY= %%N
       set flag2=0)

    if !flag1! equ 1 if !flag3! equ 1 (
       >>output.txt echo NATURAL-GAS= %%N
       set flag3=0&set flag1=0)

    if /i "%%B" equ "beps" set /a flag1+=1
    if /i "%%B" equ "electricity" set /a flag2+=1
    if /i "%%B" equ "natural-gas" set /a flag3+=1
    )

Good luck.


Report •

#5
September 22, 2010 at 17:09:48
Looks like a space delimited file to me. Each data item is separated by a space, Treat the space the same was as you would a comma and there shouldn't be a problem.

Stuart


Report •

#6
September 23, 2010 at 05:45:32
I really appreciate your help. I would give up unless there was your help. It really works for me. I run a test with both batch and gawk script. Eventually, it turns out gawk is way faster than batch file.
Before closing my question, I would like to have your invaluable comment about the study material for leaning batch script and gawk. Is there any book covering a beginner thru a expert?

Thank you again.



Report •

#7
September 23, 2010 at 06:16:36
See my sig for gawk. there's a link there for the gawk manual. Gawk is faster than batch, because all the file processing is "inside" gawk's executable. While you have to specifically iterate the file using batch.

GNU win32 packages | Gawk


Report •


Ask Question