如何使用 textmate 或 perl 中的单词列表查找和替换单词列表

How to find and replace a list of words with a list of words in textmate or with perl

我有一长串单词如下

word1
word2
word3
word4
word5
word6
word7

我想对这些词进行查找和替换,而不是单独查找一个词。我想创建一个查找目标列表,运行 这只是一次,例如我的目标列表如下。

word2
word4
word6

我该怎么做,可以在 textmate 中完成吗?显然也考虑了替代方案,但我不熟悉 perl 脚本。

我不太确定你想要什么,但听起来你想从第二个文件创建一个正则表达式并将其应用于第一个文件中的每一行。像(未经测试):

use autodie;
open my $fh, '<', $second_file;
chomp( my @lines = <$fh> );
close $fh;

my $joined = join( q{|}, map { quotemeta( $_ ) } @lines );
my $qr = qr{ $joined };

open $fh, '<', $first_file;
while( <$fh> ){
  if( /$qr/ ){
    print;
  }
}
close $fh;