Created
January 17, 2016 00:25
-
-
Save vsemozhetbyt/ca0bc3206e492b5e662c to your computer and use it in GitHub Desktop.
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
'use strict'; | |
/******************************************************************************/ | |
const path = process.argv[2]; | |
if (!path) { | |
console.log('Add the file path, please.'); | |
process.exit(); | |
} | |
/******************************************************************************/ | |
const fs = require('fs'); | |
const rl = require('readline').createInterface({ | |
input: fs.createReadStream(path, 'utf8'), //ascii utf8 utf16le | |
terminal: false, | |
historySize: 0 | |
}); | |
const outfile = fs.openSync(path.replace(/(\.[^.]+)?$/, '.new$1'), 'w'); | |
let lines = 0; | |
/******************************************************************************/ | |
rl.on('line', function(line) { | |
lines++; | |
if (lines === 1) line = line.replace(/^\uFEFF/, ''); | |
fs.writeSync(outfile, `${line}\n`, null, 'utf8'); | |
}); | |
/******************************************************************************/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment