Re: Extraction from *.txt file [message #91259 is a reply to message #91252] |
Wed, 24 June 2015 00:01   |
d.poreh
Messages: 406 Registered: October 2007
|
Senior Member |
|
|
On Wednesday, June 24, 2015 at 2:34:07 AM UTC+4:30, alx wrote:
> Le mardi 23 juin 2015 19:49:53 UTC+2, Paul van Delst a écrit :
>> Hello,
>>
>> I created a three pretend files based on your snippet below, and changed
>> the dates.
>>
>> I would use something other than IDL as a preprocessor on your text files.
>>
>> Rather than IDL, I would use grep:
>>
>> $ grep "DATE OF RAW DATA ACQUISITION" *.txt
>> blah1.txt:DATE OF RAW DATA ACQUISITION: 19-APR-2006
>> blah2.txt:DATE OF RAW DATA ACQUISITION: 20-APR-2006
>> blah3.txt:DATE OF RAW DATA ACQUISITION: 21-APR-2006
>>
>> If you just want the dates:
>>
>> $ grep "DATE OF RAW DATA ACQUISITION" *.txt | cut -d":" -f3
>> 19-APR-2006
>> 20-APR-2006
>> 21-APR-2006
>>
>> If you want filenames and dates:
>>
>> $ grep "DATE OF RAW DATA ACQUISITION" *.txt | cut -d":" -f1,3
>> blah1.txt: 19-APR-2006
>> blah2.txt: 20-APR-2006
>> blah3.txt: 21-APR-2006
>>
>> You could use this to save to a "control" file, doing something like:
>>
>> $ grep "DATE OF ...." *.txt | cut -d":" -f1,3 > ctrl.dat
>>
>> And you can read "ctrl.dat" simply in IDL -- since you want every line,
>> right?
>>
>> cheers,
>>
>> paulv
>>
>>
>> On 06/23/15 11:19, dave poreh wrote:
>>> Folks,
>>> Hi,
>>> I have many *.txt files like this:
>>>
>>> E-SAR IMAGE DATA VOLUME, VERSION 3.1, PRODUCED BY
>>> GERMAN AEROSPACE CENTER (DLR e.V.)
>>> MICROWAVES AND RADAR INSTITUTE
>>> P.O.BOX 11 16
>>> D-82230 WESSLING, GERMANY
>>> Volume created on 11-Dec-2007 16:47:13.00
>>> Copyright (c) 2007 by DLR, all rights reserved.
>>> Suggestions welcome. Please mail to:
>>> RADAR: R. Horn, E-Mail: Ralf.Horn@dlr.de
>>> PROCESSING: R. Scheiber, E-Mail: Rolf.Scheiber@dlr.de
>>> J. Fischer, E-Mail: Jens.Fischer@dlr.de
>>> ============================================================ ==================
>>> SCENE-ID: I06AGRSAR0208X1_T01
>>> VOLUME-ID: I06AGRSAR0208X1_T01_GTC_RP-MASTER
>>> DATE OF RAW DATA ACQUISITION: 19-APR-2006
>>> ============================================================ ==================
>>> I.)-VOLUME DESCRIPTION
>>> This volume includes the following files (TOC)
>>> ...
>>>
>>> And I want to extrct line 15 that says :
>>> DATE OF RAW DATA ACQUISITION: 19-APR-2006
>>>
>>> And i need just (19-APR-2006).
>>> Any help would be apprecated,
>>> Thank and have a nice SUMMER :)
>>> Cheers,
>>> Dave
>>>
>
> If you are using Windows, you don't have "grep". But you still have IDL !
>
> Assume yourfile is a string containing the name of your text file.
> First, you can put its content into a string array:
>
> IDL> s = strarr(File_Lines(yourfile))
> IDL> openR, lun, /GET_LUN, yourfile & readF, lun, s & Free_LUN, lun
>
> Then, to achieve your goal:
>
> Find the line containing the desired signature:
>
> IDL> w = where(Strpos(s, 'DATE OF RAW DATA ACQUISITION') ge 0))
>
> Extract the relevant data:
>
> IDL> data = (StrSplit(s[w], ':', /EXTRACT))[-1]
>
> If you want to have result converted to binary:
>
> IDL> data = 0.0
> IDL> reads, (StrSplit(s[w], ':', /EXTRACT))[-1], data
>
> Hoping that this can help,
> alx.
Thanks guys :). That is brilant Alx; working like a charm. Yes I do not have "grep", so i prefer IDL ways :).
Cheers,
|
|
|