Created
September 17, 2019 07:22
-
-
Save pingyen/a8d06ae276de03d554cc90190fca0a08 to your computer and use it in GitHub Desktop.
Remove duplicate lines in a file
This file contains 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
<?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