I Have a file (let's say 1.csv) having below records with 4 lines:
I want to split the file 1.txt into 2 files (lets say 2.csv and 3.csv) except header using line number and it should be as below:
Didn't get proper solution. Need some suggestion and help to proceed on this.
Use Query Record processor by configuring Record Reader as CsvReader and Record Writer as CsvSetWriter controller services.
In CsvSetWriter controller service change the property include header line to False.
Add dynamic properties to Query Record processor as
select * from Flowfile where id ❤️
select * from Flowfile where id >2
Now use 2_csv,3_csv relationships from QueryRecord processor.
id,name,age,location 1,Shailesh,35,Bangalore 2,Ajay,25,Goa 3,Sanjay,30,Chennai 4,Raman,32,Hyderabad
Output from QueryRecord Processor:
Appreciate your prompt response. Could you please share the template xml to proceed on this. I have done lot of exercise on this with no luck.
I have used the attached template and additionally used putfile processor at last to get all the files into a folder. But I am facing an issue while generating the file. It is trying to generate the files with the same file name for which it is throwing error like file name is existing, so getting the last file based on the line number count split.
Is there a way to get the files in a folder with different-2 names?
Flow is as below:
Yes,by using update attribute processor we can change the filenames.
As shown in the above screenshot use the 2 update attribute processors before PutFile processor and add new property in as
Same way add new property as
in 3_csv relationship feeding update attribute processor.
By changing the filenames like described above will keep filenames every time same.
For the first run there will be no issues because each file will have different filenames, but for the second run if you are not caring about the already stored file in the directory then use Conflict Resolution Strategy as Replace.
if you want to store all the files without any conflicts then use filename property values in update attribute processors as
UUID is unique number by using above expression language we are generating unique filename every time and there will be no conflicts.
Refernce flow.xml queryrecord-filenames-191697.xml
If the answer addressed your question,Take a moment to Log in and Click on Accept button below to accept the answer, That would be great help to Community users to find solution quickly for these kind of issues and close this thread.
Query Record Processor in this scenario seems a bit of overkill for this problem. And will require more work if you don't have auto incrementing fields.
You can use just SplitText processor to do everything.
Hey Umair, Thanks to pointing out. I was trying the same. I was trying with the following flow:
Using above case, I am getting only first file using the line number. How to get the other remaining files.
If you have any template to do so then need your help. Please share the template xml file.