##split a csv file into different csv files according to the value in headers
Could you please also help me with another scenario with the splitting a file into two csv according to the values in the header.
Example : current data :
[ {
“A”: “12345”,
“B”: “USA”,
“C”: “TestDocumentNumber”,
“Type”: “EmployeeId”,
“D”: “DBI298000020”,
“Value”: “CompanyCode”,
“ID”: “USG_1”
},
{
“A”: “23”,
“B”: “KA”,
“C”: “Testdoc”,
“Type”: “EmployeeId”,
“D”: “DBI298000123”,
“Value”: “CompanyCode”,
“ID”: “USG_3”
},
{
“A”: “27”,
“B”: “YY”,
“C”: “Testdoc”,
“Type”: “EmployeeId”,
“D”: “DBI298000123”,
“Value”: “CompanyCode”,
“ID”: “USG_3”
},
{
“A”: “98”,
“B”: “AI”,
“C”: “TestDocumentNumber”,
“Type”: “EmployeeId”,
“D”: “DBI298000123”,
“Value”: “CompanyCode”,
“ID”: “USG_3”
},
{
“A”: “21”,
“B”: “SS”,
“C”: “Testdoc”,
“Type”: “EmployeeId”,
“D”: “DBI298000123”,
“Value”: “CompanyCode”,
“ID”: “USG_3”
}
]
Requirement :
As we are getting the data like the above mentioned way, we want to split this into two files as per the requirement . we want to split this and get the data in 2 different files where, one file to contain the objects with C=Testdoc and other file with C= TestDocumentNumber
Result expected
File 1:
[
{
“A”: “23”,
“B”: “KA”,
“C”: “Testdoc”,
“Type”: “EmployeeId”,
“D”: “DBI298000123”,
“Value”: “CompanyCode”,
“ID”: “USG_3”
},
{
“A”: “27”,
“B”: “YY”,
“C”: “Testdoc”,
“Type”: “EmployeeId”,
“D”: “DBI298000123”,
“Value”: “CompanyCode”,
“ID”: “USG_3”
},
{
“A”: “21”,
“B”: “SS”,
“C”: “Testdoc”,
“Type”: “EmployeeId”,
“D”: “DBI298000123”,
“Value”: “CompanyCode”,
“ID”: “USG_3”
}
]
File 2:
[ {
“A”: “12345”,
“B”: “USA”,
“C”: “TestDocumentNumber”,
“Type”: “EmployeeId”,
“D”: “DBI298000020”,
“Value”: “CompanyCode”,
“ID”: “USG_1”
},
{
“A”: “98”,
“B”: “AI”,
“C”: “TestDocumentNumber”,
“Type”: “EmployeeId”,
“D”: “DBI298000123”,
“Value”: “CompanyCode”,
“ID”: “USG_3”
},
]
Please share your workflow
Share the output returned by the last node
Information on your n8n setup
- n8n version:
- Database (default: SQLite):
- n8n EXECUTIONS_PROCESS setting (default: own, main):
- Running n8n via (Docker, npm, n8n cloud, desktop app):
- Operating system: