Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.
Originally posted by: Tim MeagherHey,
So there are a number of ways to go about this.
If you had access to the LDR, I think that would be the best & easiest way, but I'm guessing that's not an option.
Alternately, you could use something like a python or java node to simply parse the file.
The way I would generally go about something like this if I was just using the normal core library would be as shown in the attached BRG (readDataFile.brg) & sample data (Random.txt).
Basically, I read in all of the lines of the file using a delimited node.
Then, using a filter node, I strip out the lines that I don't care about (containing header etc information).
After this, I pump that output into a java node which simply expands the line into a number of different fields.
The example I've got has each header/junk line containing the "--" characters, however you can use any regular expression in the JunkLineIdentifier parameter on the composite.
The TmpFieldName is just what the field containing the line of text will be called within the composite, prior to it being split into a number of different output fields.
The Line Delimiter is just a \r\n, and the fields are all comma separated.
This doesn't handle quotes, or escapes or anything like that.
The (optional) Fields parameter is then just a list specifying the names to use for each of the output fields. If this is specified, then the number of fields per line must match the number of fields specified.
In any case, this only handles the situation where all lines contain the same number of fields.
Anyway, I figure you should be able to use this as a basis for what you need to do.
There is most likely a better (and easier) way to do this... I just have a tendency to go into Java whenever I can't think of any easy way upfront.
If you know the number and names of the fields in advance, then you wouldn't need the java node, and could easily do this within the filter node. Just do a split based on the delimiter character.
Tim
Attachments:
Random.txt
readDataFile.brg