Split a csv file into different csv files according to the value in headers

##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:
1 Like

It looks like your topic is missing some important information. Could you provide the following if applicable.

  • n8n version:
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system:
1 Like

@Meghna_Rajeev ,

Thankyou for the help ihortom.