Created
December 14, 2018 03:45
-
-
Save naotone/2ed4594fbda5b5787d86ae0918df9f0b to your computer and use it in GitHub Desktop.
Remove row with matching values from CSV.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const targets = ['aaa@test.test', 'bbb@test.test'] | |
const input = 'data/input.csv' | |
const fs = require('fs') | |
const csv = require('csv') | |
const csvSync = require('csv-parse/lib/sync') | |
const results = [] | |
const data = fs.readFileSync(input) | |
const res = csvSync(data) | |
for( i in res){ | |
const email = res[i][0] | |
if(!targets.includes(email)){ | |
results.push(res[i]) | |
} | |
} | |
csv.stringify(results, (err, output) => { | |
fs.writeFile('data/output.csv', output, 'utf8', (err) => { | |
if (err) { | |
console.log(`Error: ${err}`) | |
} else { | |
console.log('Done') | |
} | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment