Skip to content

Instantly share code, notes, and snippets.

@bmiles
Created May 21, 2014 15:44
Show Gist options
  • Save bmiles/6bdd2bdafd1ca9f1f00a to your computer and use it in GitHub Desktop.
Save bmiles/6bdd2bdafd1ca9f1f00a to your computer and use it in GitHub Desktop.
small JS that finds and replaces tabs with a comma and renames the file to csv from asc.
var fs = require('fs');
var filePath = process.argv[2];
console.log(filePath);
fs.readFile(filePath, function (err, data) {
if (err) {
return console.log(err);
}
var newFilePath = filePath.replace(/asc/g, 'csv');
var result = data.toString().replace(/\t/g, ', ');
fs.writeFile(newFilePath, result, 'utf8', function(err) {
if (err) return console.log(err);
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment