效果
脚本
/**
* WeiCot Min Framework
* User: ajiang
* WebSite: WWW.WEICOT.COM
* Date: 2016/9/17 0056
* Time: 12:17
*/
use Weicot\Servie;
//wf 创建脚本
function createShell($orgfileName,$skuList,$startLine,$endLine){
$i=0; $f=1;
$skufile = dirname(__FILE__) . "/ori/" . $skuList . "" . ".txt";
$product_info = getFileLines($skufile, $startLine, $endLine, $method = 'rb');
$set='set path="'.dirname(__FILE__).'\GnuWin32\bin";'."\r\n";
$batName=dirname(__FILE__) . "/sh/" . $skuList."_".$f . ".bat";
file_put_contents($batName, $set, FILE_APPEND);
array_shift($product_info);
$mianBat=dirname(__FILE__) . "/sh/" . $skuList.".main.bat";
file_put_contents($mianBat,"start ".$batName."\r\n", FILE_APPEND);
foreach ($product_info as $key => $value) {
$bat=dirname(__FILE__) . "/sh/" . $skuList."_".$f . ".bat";
if($i==500){
$i=0; $f++;
$set='set path="'.dirname(__FILE__).'\GnuWin32\bin";'."\r\n";
$batName=dirname(__FILE__) . "/sh/" . $skuList."_".$f . ".bat";
file_put_contents($batName, $set, FILE_APPEND);
file_put_contents($mianBat,"start ".$batName."\r\n", FILE_APPEND);
}
//$code=getIndexCode($value);
$code=$value;
$shell='grep -A 0 "'.$code.'" '.dirname(__FILE__).'/ori/'.$orgfileName.'.txt>>'.dirname(__FILE__).'/save/'.$orgfileName."_".$f.'log.txt '."\r\n";
file_put_contents($bat, $shell, FILE_APPEND);
echo $code ."\r\n";
$i++;
}
return $bat;
}
// wf 获取命令行输入参数
function getCmd($note){
$fs = true;
do{
if($fs){
fwrite(STDOUT,$note."#");
$fs = false;
}else{
fwrite(STDOUT,'sorry file error');
}
$cmd = trim(fgets(STDIN));
}while(!$cmd);
return $cmd;
}
$orgfileName=getCmd("amz csv file");
echo "File Dir:".dirname(__FILE__).'/ori/'.$orgfileName.'.txt'."\r\n";
$skuList=getCmd("sku file");
echo "File Dir:".dirname(__FILE__) . "/ori/" . $skuList . "" . ".txt"."\r\n";
createShell($orgfileName,$skuList,$startLine=1,$endLine=5000);
转载请注明:(●--●) Hello.My Weicot » win 下 使用php 生成 grep 多开查找 脚本