Created
February 14, 2017 20:24
-
-
Save jeremyckahn/edb2f3971bd97d7af30c5d027745f319 to your computer and use it in GitHub Desktop.
Delete random lines in a file
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 | |
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