Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ~/naive-file.txt
- ~/old-text.txt
- ~/new-text.txt
- $ cat ~/naive-file.txt
- Sed id ligula quis est convallis tempor.
- This is the old text.
- It might have multiple lines and some special characters like these { & % #)!
- etc...
- Nunc aliquet, augue nec adipiscing interdum, lacus tellus malesuada massa, quis
- varius mi purus non odio.
- $ cat ~/old-text.txt
- This is the old text.
- It might have multiple lines and some special characters like these { & % #)!
- etc...
- $ cat ~/new-text.txt
- This is the new text.
- It could also have multiple lines and special characters like these { & %
- etc...
- Sed id ligula quis est convallis tempor.
- This is the new text.
- It could also have multiple lines and special characters like these { & %
- etc...
- Nunc aliquet, augue nec adipiscing interdum, lacus tellus malesuada massa, quis
- varius mi purus non odio.
- #!/usr/bin/perl
- use warnings;
- use strict;
- open my $ot, '<', 'old-text.txt' or die $!;
- chomp( my @lines = <$ot> );
- open my $nt, '<', 'new-text.txt' or die $!;
- my %replace;
- @replace{@lines} = <$nt>;
- chomp for values %replace;
- my $regex = join '|', map quotemeta, @lines;
- open my $in, 'naive-file.txt' or die $!;
- while (<$in>) {
- s{(.*)}{$replace{$1} // $1}e;
- print;
- }
- my $regex = join '|', map quotemeta, sort { length $b <=> length $a } @lines;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement