代码之家  ›  专栏  ›  技术社区  ›  Gerhard

多行搜索和替换工具

  •  20
  • Gerhard  · 技术社区  · 16 年前

    #include "../DiscreteIO/Discrete.h"
    #include "../PCI/pci.h"
    #include "../Arinc429/ARINC429.h"
    

    具有

    #include "../PCI/pci.h"
    #include "../DiscreteIO/DiscreteHW.h"
    #include "../DiscreteIO/Discrete.h"
    

    我已经尝试了两个工具,用于这种类型的搜索和替换。 Wildedit Actual search and replace 两者似乎都是优秀的工具,但都是共享软件。有人知道类似的工具吗?有免费的吗?还是该放弃一些钱了?

    澄清:

    完成一个项目 在这种情况下意味着一千多个c文件。文本编辑器一次只能执行一个文件(Textpad、程序员记事本)或所有打开的文件(nodepad++)。我没有试过其他的编辑,但我想他们也会有类似的问题。如果我错了,请纠正我。

    像sed&awk是一个解决方案,但存在问题,因为我不经常使用它们,并且需要花一些时间来做一些事情,因为我不是工具方面的专家。

    所有这些。。。

    超编辑可以工作,但我已经有了一个编辑器,如果我只是想用它作为一个搜索和替换工具,价格是很高的。

    Sed、AWK和基于正则表达式的工具可以工作,但在某些情况下可能会带来麻烦。

    野生编辑可以工作,并没有那么昂贵。

    我最终的决定是使用我的正则表达式技能。

    13 回复  |  直到 16 年前
        1
  •  12
  •   Rich    11 年前

    JetBrains系列IDE: IntelliJ RubyMine PHPStorm etc将执行多行搜索和替换。

    选择有问题的文本,然后按 ctrl-shift-F \n )

        2
  •  9
  •   matt wilkie    12 年前

    请参见此处的FAQ条目 http://sed.sourceforge.net/sedfaq4.html#s4.23.3

    如果需要匹配 文本(可出现在任意数量的 文件中的时间),其中 块的内容在中是已知的 使用

    Sed可用于Windows。看见 http://gnuwin32.sourceforge.net/packages/sed.htm

        3
  •  4
  •   Zsolt Botykai    16 年前
    cd $PROJECTDIR && find . -iname '*.*' -exec vim -c 's:^first line of text\nsecond line of text\n3rd line of text:new 1st line\rnew 2nd\rnew 3rd:' -c 'w!' -c 'q' {} \;
    

        4
  •  4
  •   Kissaki    6 年前

    Visual Studio Code 具有非常好的全局搜索和替换功能。我只是使用它对许多文件进行多行更改,包括一些带有捕获和替换的Regexp搜索。

    • 开放VS代码
    • 文件打开文件夹,打开文件所在的文件夹
    • 打开文件并选择要替换的文本
    • 如果您选择了一个文本,它将自动填充,甚至多行。否则,请输入文本,使用SHIFT+enter插入换行符,并可以选择启用Regexp。
    • 输入替换文本
    • 单击更改项以并排预览更改
    • 使用“全部替换”按钮(CTRL+ALT+Enter)应用和保存更改
        5
  •  3
  •   Bruno Vincent    7 年前

    唯一能在一次拍摄中交钥匙的是dreamweaver。。。。 enter image description here

        7
  •  2
  •   sporker    8 年前

    我不允许发表评论,但公认的解决方案引用了一个似乎不可靠的例子。第18行应为:

    s,[/\.*[],\\&,g
    

    s,[/\[.*],\\&,g
    

    后者会向现代sed(如果您在*BSD中,则称为“gsed”)抱怨第18行的未终止表达式。

        8
  •  1
  •   Jason Airlie Jason Airlie    16 年前
        9
  •  1
  •   Simon Jones Simon Jones    16 年前

    我找到的最好的工具是一个叫做 BK ReplaceEm . 这个界面需要一点时间来适应,但是学习如何使用它是值得的。该工具非常强大,允许您使用或不使用正则表达式进行多行替换。

        10
  •  0
  •   Stephen Denne    16 年前

    Ultraedit

    a tutorial on multi-line find & replace 您可以将其用于“ replace in files “应用于多个文件。

        11
  •  0
  •   Yann Semet    16 年前

        12
  •  0
  •   PhiLho    16 年前

    有许多适用于Windows的搜索/替换工具,或多或少功能强大,很多都是免费的。
    目前,我使用的是 FileMenu Tools
    我也有RJL软件的 Simple Search-Replace (无REs),乌龟属作者 grepWin ,支持正则表达式和许多选项,还有一些我过去使用过的选项。

    我确实记得这些带有多行搜索/替换字段的免费工具,但我手头没有它们的名称。

        13
  •  0
  •   Jason Plank Maksim Kondratyuk    13 年前
    #see docs at the bottom 
    use strict;
    use warnings;
    use Cwd;
    
    use File::Find;
    
    my $search_patternFilePath=$ARGV[0] ;
    my $replace_patternFilePath =$ARGV[1];
    my $file_pattern = $ARGV[2];
    
    # Usage
    
    (@ARGV == 3 ) || die ("Usage: FindAndReplace.pl pathToFileContaingTheMultiLineSearchText FullPathToFileContainingMultiLineReplaceText FilePattern . Example: perl MultiLineFindAndReplace.pl \"D:\Opera\New Folder\search.txt\" \"D:\Opera\replace.txt\" bak");
    
    
    
    find(\&d, cwd);
    
    sub d {
    my $file = $File::Find::name;
    $file =~ s,/,\\,g;
    
    return unless -f $file;
    return unless $file =~ /$file_pattern/;
    
    my $searchPatternString = &slurpFile ( $search_patternFilePath ) ; 
    my $replacePatternString = &slurpFile ( $replace_patternFilePath ) ; 
    my $fileStr = &slurpFile ( $file ) ; 
    
    $fileStr =~ s/$searchPatternString/$replacePatternString/igo ; 
    open(FILEHANDLE,">$file") || die "cannot open output file";
    print (FILEHANDLE "$fileStr");
    close FILEHANDLE ;
    
    }
    
    sub slurpFile 
    {
    my $file = shift ;
    print "\$file is $file" ;
    local( $/, *FILE ) ; 
    open (FILE , $file) or 
    die "Cannot find $file !!! " ; 
    my $fileString = <FILE>; #slurp the whole file into one string !!! 
    close FILE ;
    return $fileString ;
    }
    #Purpose : performs recursive find and replace based on pеrl regexes from the current directory
    #the search and replace is case insensitive
    #Usage
    #perl MultiLineFindAndReplace.pl "D:\Opera\New Folder\search.txt" "D:\Opera\replace.txt" bak