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.
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:
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.