Created 06-25-2018 04:39 PM
Hello,
The header of my csv file contains some special character. Example
Name,T&C_Test,Date_of_(Transformation)
And I want to use the processor Replace Text to edit only the header. When I use the Append Stratesy for the entire text, it dosen't work.
Help plz. Thank you
Created 06-25-2018 07:42 PM
You can use a regular expression to isolate the header line (for example search the entire content, start at the beginning using "^", and stop on the first newline) and replace it with what you'd like to have. You'l have to test out different regex strings to see what works for you but this should get you started.
Created 06-26-2018 12:08 PM
I tried with ^ at the beginning of the expression. No results 😕
Created 06-26-2018 12:52 PM
Please take a look at the following HCC thread:
https://community.hortonworks.com/questions/35203/hi-where-can-i-find-the-rules-of-nifis-regex-langu...
That thread also links to this website, which you can use to create your expressions and directly copy them to NiFi. You may not be using the correct syntax if it isn't working, so please verify with this website:
Created on 06-27-2018 03:00 AM - edited 08-17-2019 06:20 PM
As suggested by @anarasimham With Start of the string(^) in Replace text processor should match only the first line.
Make sure you are having matching regex that exclude special character.
Example:
in the above configs i'm matching only the first line in the flowfile and adding new to the first line only and all the other contents will be untouched.
input:
hi
hello
Output:
newhi
hello
(or)
You can use one of the way that i have suggested in this link, please refer to the shared link and choose the method that will best fit for your case.
If you are still having issues please share some sample data with header and the expected output?
Created 06-27-2018 09:33 AM
@Shu Thank you for your response when I tried this regex expression :
^[!@#$%^&*(),.?":{}|<>]
It changed only the first occurance of a special character.
I have in input this csv file :
Name,T&C_Test,Date_of_(Transformation),date_/_of _deliverance
1,1457,26/12/2016,14/12/2017
2,4789,18/04/2017,03/09/2018
I expect an output file like this one:
Name,TC_Test,Date_of_Transformation,date_of _deliverance
1,1457,26/12/2016,14/12/2017
2,4789,18/04/2017,03/09/2018
Created on 06-29-2018 09:18 AM - edited 08-17-2019 06:20 PM
Use one of the way from the above shared link to take out only the header from the csv file then in replace text keep the
then search for (&|\(|\)|\/_|\s) and in Replacement value keep as empty string, now we are searching for all the special characters in the header flowfile then replacing with empty string.Now add this header flowfile with the other non header flowfile. all the explanation and template.xml are shared in this link.