Removing certain lines from a text file
Solved
Cybmatt
Posted messages
4
Status
Member
-
Cybmatt Posted messages 4 Status Member -
Cybmatt Posted messages 4 Status Member -
Hello,
I have an automated processing task to implement using a Windows batch file. Here is my issue:
I have a whole set of flat files (CSV format) whose separator is the semicolon. They all have the same structure:
- a first line whose first three characters are "00;"
- n lines whose first three characters are "01;"
Example:
00;20001;ABC;20190617;1224;19;01;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
01;123456789;20190617;ABCD;81257033099;20001201906170000001;EUR;1906;25;FR;09055478004;05;1;ZV13;717409;1;1912875;;;;;16;;;;;;;0000048235;;;;;;;;;;;;;;;;1;;;;;;;;;;;21;1;ZPCC;1912875;EUR;XXX AABB
01;123456789;20190617;ABCD;81257033099;20001201906170000002;EUR;1906;25;FR;09045845016;05;1;ZV13;717409;1;1912875;;;;;16;;;;;;;0000048235;;;;;;;;;;;;;;;;1;;;;;;;;;;;21;1;ZPCC;1912875;EUR;XXX CC DD
My objectives:
- Merge all CSV files into a single CSV file named "FVMA_global.csv"
- In this last file, remove all lines starting with "00;" and create a clean file named "FVMA_global_<dateofday>.csv"
For the first step, no problem, I used this code:
FOR /f %%i in ('dir /B *.csv') do ( IF %%i NEQ FVMA_global.csv type %%i>>FVMA_global.csv )
This does produce a file named "FVMA_global.csv".
I cannot manage the second part of the processing. I imagine a FOR /F loop is needed as well, but I cannot test for the first three characters, and ensure, based on this test, to put the parsed line content into a new .csv file (which is the final file, cleaned of lines starting with "00;").
Many thanks in advance for your valuable help.</dateofday>
I have an automated processing task to implement using a Windows batch file. Here is my issue:
I have a whole set of flat files (CSV format) whose separator is the semicolon. They all have the same structure:
- a first line whose first three characters are "00;"
- n lines whose first three characters are "01;"
Example:
00;20001;ABC;20190617;1224;19;01;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
01;123456789;20190617;ABCD;81257033099;20001201906170000001;EUR;1906;25;FR;09055478004;05;1;ZV13;717409;1;1912875;;;;;16;;;;;;;0000048235;;;;;;;;;;;;;;;;1;;;;;;;;;;;21;1;ZPCC;1912875;EUR;XXX AABB
01;123456789;20190617;ABCD;81257033099;20001201906170000002;EUR;1906;25;FR;09045845016;05;1;ZV13;717409;1;1912875;;;;;16;;;;;;;0000048235;;;;;;;;;;;;;;;;1;;;;;;;;;;;21;1;ZPCC;1912875;EUR;XXX CC DD
My objectives:
- Merge all CSV files into a single CSV file named "FVMA_global.csv"
- In this last file, remove all lines starting with "00;" and create a clean file named "FVMA_global_<dateofday>.csv"
For the first step, no problem, I used this code:
FOR /f %%i in ('dir /B *.csv') do ( IF %%i NEQ FVMA_global.csv type %%i>>FVMA_global.csv )
This does produce a file named "FVMA_global.csv".
I cannot manage the second part of the processing. I imagine a FOR /F loop is needed as well, but I cannot test for the first three characters, and ensure, based on this test, to put the parsed line content into a new .csv file (which is the final file, cleaned of lines starting with "00;").
Many thanks in advance for your valuable help.</dateofday>