Delete Records Meeting a Specified Condition from a CSV File and Store Them into a New File

Problem description & analysis

Below is CSV file csv.csv:

id,price,detail

A01,30,detail1

A02,10,detail2

A03,40,detail3

We are trying to delete records where id is A01 and price is 30 and store them into a new CSV file. Below is the expected result:

id,price,detail

A02,10,detail2

A03,40,detail3

Solution

Write the following script p1.dfx in esProc:

A

1

=file("csv.csv").import@ct()

2

=number.split@cp()

3

=A1.select(id!=A2(1) && price!=A2(2))

4

=file("result.csv").export@ct(A3)

Explanation:

Set cellset parameter number, whose value is A01,30.

A1   Import the CSV file as a table sequence.

A2  Split the number string into a sequence according to appropriate data types.

A3  Filter away records where id isn’t A01 and price is not 30. =A1.select([id,price]!=A2)is one choice, but it generates a [id,price] sequence for each record. That will consume too much memory space and CPU.

A4  Export A3’s result to result.csv.

Q & A Collection

https://stackoverflow.com/questions/62588154/delete-item-from-csv-file-using-java