Page 1 of 1

split csv-file by in-file criteria

Posted: 16 Oct 2013 02:08
by ajaekel
Hello everyone,

I would like to split an existing csv-file into multiple files by an in-file criteria - let's call it filename.

I already found a script for doing this by amount of lines in this forum - but as I am not a coder, I am unfortunately not able to translate this into my purposes.

Does anyone know how to solve this?

Thanks & regards,
Achim

Re: split csv-file by in-file criteria

Posted: 16 Oct 2013 06:50
by foxidrive
Describe your problem with examples - someone here can figure out the most appropriate and robust method to solve it.

Re: split csv-file by in-file criteria

Posted: 18 Oct 2013 04:21
by ajaekel
Hi again,

for example, my csv-file contains the following rows:

record1;this is a test;filename1
record2;this is another test;filename2
record3;this is a 3rd test;filename1
record4;this is a 4th test;filename3
...

What I would like to get are 3 file containing the following records and named like the column filename (3rd column of file):

filename1:
record1;this is a test;filename1
record3;this is a 3rd test;filename1

filename2:
record2;this is another test;filename2

filename3:
record4;this is a 4th test;filename3

Is this somehow possible?

Thanks in advance & kind regards,
Achim

Re: split csv-file by in-file criteria

Posted: 18 Oct 2013 12:21
by foxidrive
Your request doesn't give enough information about which lines go into which files, unless your CSV file is really only 4 lines long.

Re: split csv-file by in-file criteria

Posted: 18 Oct 2013 23:51
by pumi
try this

Code: Select all

@ECHO OFF
SETLOCAL ENABLEEXTENSIONS
SETLOCAL ENABLEDELAYEDEXPANSION

FOR /F "tokens=1,2,3 delims=;" %%A in (test.csv) do @echo %%A;%%B;%%C >> %%C

Re: split csv-file by in-file criteria

Posted: 19 Oct 2013 00:53
by foxidrive
That splits every record (and adds a space to the end).

The OP wants something a little different...