Skip to content

Instantly share code, notes, and snippets.

@jeremyckahn
Created February 14, 2017 20:48
Show Gist options
  • Save jeremyckahn/2bc1f41e887efb96cb9ce48befc52261 to your computer and use it in GitHub Desktop.
Save jeremyckahn/2bc1f41e887efb96cb9ce48befc52261 to your computer and use it in GitHub Desktop.
delete-random-lines.js
// 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