Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Remove duplicate lines in a file
$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) {
$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