Issue
I have over 500 site and i want to replace a specific word in all of them with random words from a text file.
Folders structure
www
- site1
- - idex.html
- site2
- - index.html
-site3
- - index.html
Word name: Dashemd
Txt file content one world per line, like this:
Hemd.txt:
Blue
Red
Pink
Green
More …
So i need replace word dashemd
in index.html of all folders with list of words in hemd.txt
file randomly.
Could you please help me?
I tried to replace with static word but i couldn’t do this with random words from txt file
find ./ -type f -exec sed -i -e 's/dashemd/newworld/g' {} \;
Solution
To replace each repetitive 'dashemd' words:
find ./ -type f -name '*.html' -exec perl -i -MFile::Slurp -pe '
my @words = split /\n/, read_file("Hemd.txt");
s/dashemd/$words[rand(@words)]/g;
' -- {} +
You need File::Slurp module, libfile-slurp-perl
Debian package. A must have.
Can also be installed via cpan -i File::Slurp
Answered By - Gilles Quénot Answer Checked By - Katrina (WPSolving Volunteer)