I have a folder with 100s of CSV files. What I want is a batch file to process each file by looping 1 by 1 and delete any duplicate rows under it.
Other than The duplicate lines there are some rows which I want to delete based on 2nd columns value.
Name,Test Name
City,Mumbai
Country,IN
I want to delete rows where second column of the row matches IN
Is it possible to do so with a windows batch script?
The following untested batch script does the job assuming
1) the duplicate rows to be deleted are in sequence;
2) the key field for deletion starts as ,IN
@echo off & setlocal EnableDelayedExpansion
pushd Your_Folder
for %%i in (*.csv) do (
set row=
for /F “delims=” %%j in (‘type “%%i” ^| find /V “,IN”‘) do (
if not “%%j”==”!row!” echo.%%j>> “%%~ni.tmp”
set row=%%j
)
)
del *.csv
ren *.tmp *.csv
popd