Solved Compare and Delete Records in Batch Script

January 30, 2018 at 16:22:28
Specs: Windows 10
Hi ,

I am not sure if we can do using batch scripting, please let me know if there is a possibility.

I have a file which has 20000-40000 lines as below

ABC,Received,100001,Updated
ABC,Not Received,100001,Not Updated
CDF,Paid,10002,Updated
XYZ,In Progress,10098,Not Updated
TRE,Unknown,145678,Updated
TRE,Unknown,145678,Not Updated

I am trying to delete based on the third column, if there are two lines with updated and Not updated and the value in the third column is same, I am tring to delete the Not updated lines as below

ABC,Received,100001,Updated
CDF,Paid,10002,Updated
XYZ,In Progress,10098,Not Updated
TRE,Unknown,145678,Updated

I am able to get the individual records, but I am not sure on how to compare the previous records and delete from the file.

Please tell me any logic to achieve this.

Regards,Anu



See More: Compare and Delete Records in Batch Script

Report •

#1
January 30, 2018 at 19:36:35
✔ Best Answer
This seemed to work in my tests:
@echo off>new2 & setlocal enabledelayedexpansion
for /f "tokens=*" %%x in (ana) do (
call :bb "%%x"
)
more new2
goto :eof


:bb
set line=%~1
echo %line% | find /i ",updated">>new2&&(
for /f "tokens=3 delims=," %%x in ("%line%") do set prev=%%x
) || (
echo %line% | find /i /v "%prev%,not updated">>new2
)


Report •
Related Solutions


Ask Question