Skip to content

Instantly share code, notes, and snippets.

@pingyen
Created September 17, 2019 07:22
Show Gist options
  • Save pingyen/a8d06ae276de03d554cc90190fca0a08 to your computer and use it in GitHub Desktop.
Save pingyen/a8d06ae276de03d554cc90190fca0a08 to your computer and use it in GitHub Desktop.
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