vim正则替换

发布时间:2021-07-14 18:20:13 阅读:1084次

1 #*/1  * * * *   /app/php5/bin/php /home/yansiyu/index.php
2 #*/1  * * * *   /app/php5/bin/php /home/yansiyu/cli.php
3 #*/11  * * * *  /app/php5/bin/php /home/yansiyu/cli.php

:1,$s/#\*\/\d\{1,\}/&/gc 


# 1asdfffffffffffffasdf  [aaa] > /dev/null
# 2asdf [bbbbbbbbbbb] > /dev/null
# 3aaaaaaa     [123123123123] > /dev/null

:1,$s/\[.*\].*/&/gc


35 lynx取得纯文本的链接


 36 lynx --dump url
 37
 38
 39 1、#将行前的数字符号去掉
 40 :1,$s/\(\d*\)\.//c
 41
 42 2、#将域名去掉
 43 :1,$s/http:\/\/www.phpjx.com\/dev\/2012//c
 44
 45 3、#将第一个出现的/改为www.phpjx.com
 46 :1,$s/\//http:\/\/www.phpjx.com\//c
 47
 48 4、#将gaoqing后面的数字去掉
 49 :1,$s/dev_\(\d*\)/dev/c
生成以上的vim替换命令生成new_*.txt与old_*.txt
再调用php,替换
 1 <?php
  2 $id=$_GET["id"];
  3 if($id==""){
  4         echo "noid";
  5 exit;
  6 }
  7
  8 if(!file_exists("new_".$id.".txt")){
  9 echo "new_".$id."not exist";
 10 exit;
 11 }
 12
 13 if(!file_exists("old_".$id.".txt")){
 14 echo "old_".$id."not exist";
 15 exit;
 16 }
 17
 18 $file_handle = fopen("new_".$id.".txt", "r");
 19 while (!feof($file_handle)) {
 20   $line = fgets($file_handle);
 21   $array_new[]=trim($line);
 22 }
 23 print_r($array_new);
 24
 25 $file_handle = fopen("old_".$id.".txt", "r");
 26 while (!feof($file_handle)) {
 27   $line = fgets($file_handle);
 28   $array_old[]=trim($line);
 29 }
 30 print_r($array_old);
 31
 32 $content=file_get_contents("http://www.phpjx.com/dev/".$id.".html");
 33 if(is_array($array_old)){
 34 foreach($array_old as $key=>$value){
 35 $content=str_replace($value,$array_new[$key],$content);
 36 }
 37 }
 38 print_r($content);
 39 file_put_contents("//mnt//virtual_xp//tuku/tuku_new/".$id.".html",$content);
 40 fclose($file_handle);
 41 ?>

如有问题,可以QQ搜索群1028468525加入群聊,欢迎一起研究技术

支付宝 微信

有疑问联系站长,请联系QQ:QQ咨询

转载请注明:vim正则替换 出自老鄢博客 | 欢迎分享