Removing certain lines from a text file

Solved
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>

1 answer

  1. dubcek Posted messages 18627 Registration date   Status Contributor Last intervention   5 660
     
    hello
    and with findstr ?
    extract the lines that do not start with 00; (i haven't tested)
    findstr /r /v /c:^00; fichier.csv

    or with "
    findstr /r /v /c:"^00;" fichier.csv
    0
    1. Cybmatt Posted messages 4 Status Member
       
      Will it exclude only lines starting with "00;"? What if a line contains the string "00;" somewhere in the middle (not at the start)? Will that same line also be excluded?
      0
    2. dubcek Posted messages 18627 Registration date   Status Contributor Last intervention   5 660
       
      The ^ means only at the start of the line
      see how to findstr
      0
    3. Cybmatt Posted messages 4 Status Member
       
      it works great, I did it like this:
      findstr /r /v /c:"^00;" FVMA_global.csv>> FVMA_global2.csv
      0