<?php
error_reporting(0);
echo"\n"."輸入要整理的文件:"."\n";
$dic=trim(fgets(STDIN));
$file=file($dic);
$array=preg_replace('/($\s*$)|(^\s*^)/m','',$file); //消除空行
$new_array=array_values(array_unique($array));//消除重復行
$new_filename="new_". basename($dic); www.2cto.com
if(file_put_contents("$new_filename",join("\r\n",$new_array))){
echo"------------------------------------------"."\r\n";
echo"\n"."去除重復完畢!"."\r\n" ;
echo"去除重復後的文件為:"."\r\n";
echo dirname(__FILE__).DIRECTORY_SEPARATOR."$new_filename"."\r\n";
echo"------------------------------------------"."\r\n";
}
else{
echo"------------------------------------------"."\r\n";
echo"錯誤!"."\r\n";
echo"找不到文件!請檢查輸入路徑是否存在!"."\r\n";
echo"------------------------------------------"."\r\n";
exit();
}
?>
摘自 http://hi.baidu.com/nginxshel