zoukankan      html  css  js  c++  java
  • 批量修改文件

    我们一个平台有好多项目配置,如果发现一个平台性bug,所有配置都要修改。
    一个配置一个目录,一个一个改非常麻烦,我们有个平台有几十个项目配置,手工改工作量太大了。

    写个工具处理这些文件:

    
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    use  strict;
     
    if ( @ARGV [0] !~ m/xxx_cfg.c/)
    {
         exit (0);
    }
    my  $file  "< " . @ARGV [0];
    open (CFG_FILE, $file )|| die ( "Can't open read file" );
    my  $line  "" ;
    my  @lines  = ();
    @lines  = <CFG_FILE>;
    close (CFG_FILE);
     
    $file  "> " . @ARGV [0];
    open (CFG_FILE, $file )|| die ( "Can't open write file" );
    foreach  $line  ( @lines )
    {
         if  ( $line  =~ m/cfg_KeyWord/)    #查找关键字
         {
             $line  =~ s/AAA/BBB/;    #在该行替换内容
         }
         print  CFG_FILE ( $line );
    }
    close (CFG_FILE);

    再在配置目录里调用批处理:
    FOR /R %A IN (*.c) DO perl e: oolsstr_file.pl %A
    就会把所有需要修改的都改了。

    当然提交时要检查一下,代码还是要人把关的。


  • 相关阅读:
    平衡二叉树之RB树
    平衡二叉树之AVL树
    实现哈希表
    LeetCode Median of Two Sorted Arrays
    LeetCode Minimum Window Substring
    LeetCode Interleaving String
    LeetCode Regular Expression Matching
    PAT 1087 All Roads Lead to Rome
    PAT 1086 Tree Traversals Again
    LeetCode Longest Palindromic Substring
  • 原文地址:https://www.cnblogs.com/keanuyaoo/p/3343279.html
Copyright © 2011-2022 走看看