[Solved] Using a .csv file as a data pool for the sed function


Use Perl. Read the CSV file into a hash, build a regular expression from the hash keys, and do a global subtitution on the text using the hash to translate.

It looks like this

use strict;
use warnings;
use 5.010;
use autodie;

my $str = <<'__END_TEXT__';
The ripple-necked bird sang melodies by the curling river while
the hooded tiger glowered in the tree beneath her, just out of reach.
__END_TEXT__

open my $fh, '<', 'words.csv';
my %patterns = map {
   chomp;
   split /,/, $_, 2;
} <$fh>;

my $re = join '|', sort { length $b <=> length $a } keys %patterns;

$str =~ s/\b($re)\b/$patterns{$1}/g;

say $str;

output

The ripple-necked snake sang melodies by the curling stream while
the hooded tiger glowered in the bush beneath her, just out of reach.

2

solved Using a .csv file as a data pool for the sed function