Skip to content

Instantly share code, notes, and snippets.

@naotone
Created December 14, 2018 03:45
Show Gist options
  • Save naotone/2ed4594fbda5b5787d86ae0918df9f0b to your computer and use it in GitHub Desktop.
Save naotone/2ed4594fbda5b5787d86ae0918df9f0b to your computer and use it in GitHub Desktop.
Remove row with matching values from CSV.
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