-2

I have a long list of words as follows

word1
word2
word3
word4
word5
word6
word7

I would like to do a find and replace on these words without individually finding a word. Id like to create a list of find targets and run this just once eg my target list would be as below.

word2
word4
word6

How can I do this and can it be done in textmate. Alternatives also considered obviously but I'm not familiar with perl scripts.

Sebastian Zeki
  • 6,690
  • 11
  • 60
  • 125

1 Answers1

1

I'm not exactly sure what you want but it sounds like you want to create a regular expression from the second file and apply it to each line in the first. Something like (untested):

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;
shawnhcorey
  • 3,545
  • 1
  • 15
  • 17