Hi,
I have a batch file that combines multiple CSV files that have similar file names. How do I add a script to remove the extra header rows?
This is what I currently have. It runs with no issues, I want to keep the 1st row as header, but remove the extra header rows that result from the multiple CSV files.
copy \\MI\Master\Export\recondata*.csv “\\MI-MKE-GOV\RCP_Master\Export\recondata all import.csv”
copy \\MI\Master\Export\aged_items*.csv “\\MI-MKE-GOV\RCP_Master\Export\aged_items all import.csv”
Pause
TRACT-NAME,PRCSMO,CONO,CONAME,CCNO,CCDESC,ACCTNO,ACCTDESC
(“TRACT-NAME” was just an example I was working with, you need to use an actual header snippet/sample for the filter.)
I ran this as a short test, replacing TRACT-NAME as the tag, and it worked ok:
@echo off & setlocal
set headertag=PRCSMO
:: following correspondes to your: copy \\MI\Master\Export\recondata*.csv “\\MI-MKE-GOV\RCP_Master\Export\recondata all import.csv”
:: test4 is the counterpart of “all import.csv”
copy test+test2+test3 test4
:: this gets ALL the headers…
find “%headertag%”<test4>work
:: now just capture one header into “work”
set /p x=<work
echo %x%>work
:: now append just the data-content, sans headers, from the combined file to “work” find /v “%headertag%”<test4>>work
:: maybe this was the ‘missing step’? “work” was the final destination of my solution.
move /y work “all import.csv”
::======== end batch
I think my solution is somewhat awkward, but it worked in my test.