Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Remove duplicate lines in a file
<?php
$targets = array_slice($argv, 1);
foreach ($targets as $target) {
$map = array();
foreach (explode("\n", file_get_contents($target)) as $line) {
if (isset($map[$line]) === true) {
continue;
}
$map[$line] = true;
}
file_put_contents($target, implode("\n", array_keys($map)));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.