Skip to main content
Question

Interpreting a text file through sequential reading


Forum|alt.badge.img

I have a text file which represents a log of activity in using a software licence. The license server records each issue and return of the licence on a seperate line of the file.

 

 

Every day, an entry in the file reads something like "DATESTAMP: YYYYMMDD"

 

Then there are a series of lines which read "TIMESTAMP: HHMMSS"

 

 

What I want to do is associate each timestamp with the latest datestamp to appear above it in the file, and create this as an attribute on each timestamp feature.

 

 

Does anyone have any suggestions?

Thanks in advance, Riley

4 replies

david_r
Celebrity
  • October 27, 2014
Hi,

 

 

look into the multiple feature support of the AttributeCreator (http://docs.safe.com/fme/html/FME_Transformers/Default.htm#Transformers/attributecreator.htm), which can reference previous or subsequent features to join your TIMESTAMP features with the preceeding DATESTAMP features.

 

 

David

 

 

Forum|alt.badge.img
  • Author
  • October 27, 2014
Hi David

 

 

Thanks - that's useful, I wasn't aware of that. Unfortunately, I still don't know how many features to tell the AttributeCreator to look backwards for, as this varies depending on the number of licence issues on a given day. Is there a way that I can test for a certain condition within this e.g. contains "datestamp"?

 

 

Thanks, Riley

gio
Contributor
Forum|alt.badge.img+15
  • Contributor
  • October 27, 2014
Hi,

 

 

You can use a txt reader, so it reads textline_data.

 

Expose line_number (if u intend to write it to a textfile again)

 

Connect a stringsearcher with a regexp to find DATESTAMP: (.*)

 

Conne the found port to a variableSetter: variablevalue = matched_parts{0} (this stream does not connect further to anyting, it ends there)

 

 

 

Connect  a variableretriever to the "not found" port and retrieve the variable u set datestamp to and assign it to a attribute (for instance "d_Stamp").

 

 Then connect to a  stringsearcher and serach  for TIMESTAMP: (.*) and assign it (matched_parts{0} ) to a attribute (for instance t_stamp.

 

Now you should have the textfile read an all t_stamps belonging to a d_stamp are related.

 

 

(this is because of sequential reading and the fact that the textfile is ordered)

 

 

 

Forum|alt.badge.img
  • Author
  • October 27, 2014
Gio - this has solved for me. Thank you very much to both of you for quick responses.

Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings