Reputation: 883
I want to extract filename and store the filename in one of the existing column in the CSV file. How to do this? Which processor to use? what configuration? Ex- i have a filename 'FE_CHRGRSIM_20171207150616_CustRec.csv' and i want to extract ''FE_CHRGRSIM_20171207150616' and store this value under an existing column in the Same CSV file. Please help. TIA
Upvotes: 0
Views: 277
Reputation: 12083
Usually the "real" file name is available as an attribute on the flow file called "filename". You can use UpdateRecord with a Replacement Strategy of "Literal Value"; add a user-defined property called /filename
and set the value to ${filename:substringBeforeLast('.')}
. You'll need to make sure that the "filename" field is added to your schema (either by UpdateRecord or manually). If you won't know your CSV schema ahead of time you can use InferAvroSchema and it will try to figure it out.
If UpdateRecord and the schema stuff doesn't seem to be working for you, an alternative (since it's CSV) is to use ReplaceText, match the entire line, then replace with that value followed by ,${filename:substringBeforeLast('.')}
. That should add the filename (with extension removed) as the last column in the outgoing CSV.
Upvotes: 1