Created
February 14, 2017 20:48
-
-
Save jeremyckahn/2bc1f41e887efb96cb9ce48befc52261 to your computer and use it in GitHub Desktop.
delete-random-lines.js
This file contains hidden or 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
// Usage: | |
// node delete-random-lines.js some-file.txt | |
require('fs').readFile(process.argv[2], 'utf-8', (err, file) => { | |
const lines = file.split('\n'); | |
const linesToDelete = Math.round(lines.length * 0.1); | |
for (let i = 0; i < linesToDelete; i++) | |
lines.splice( | |
Math.floor(Math.random() * lines.length), | |
1 | |
); | |
console.log(lines.join('\n')); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment