Skip to content

Instantly share code, notes, and snippets.

@jeremyckahn
Created February 14, 2017 20:24
Show Gist options
  • Save jeremyckahn/edb2f3971bd97d7af30c5d027745f319 to your computer and use it in GitHub Desktop.
Save jeremyckahn/edb2f3971bd97d7af30c5d027745f319 to your computer and use it in GitHub Desktop.
Delete random lines in a file
// Usage:
// node delete-random-lines.js some-file.txt
const fs = require('fs');
const lines = fs.readFileSync(process.argv[2], 'utf-8').split('\n');
const lineToDelete = Math.round(lines.length * 0.1);
for (let i = 0; i < lineToDelete; 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