I need a shell script to find html files, identify a word in the file and replace dummy text with that word

I have several paralell directories, each with a file named mes.html
In each of these files is one of several standard words, like pure, planet or factor.  After each standard word is a number, like 12 or 08.
Based on which word is in the mes.html file, I need to replace the word thumb.jpg with a the standard word in the file, like pure 08.jpg.  Even better would be no space in the replacement text.

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

some more clarity is required.  

you have mes.html in too many directories.  this mes.html has words pure08, planet03, factor04 etc happening inside them.

you want pure08 to be changed to pure08.jpg and the following

pure08  ->  pure08.jpg
planet03 -> planet03.gif

and so on...

is this right??

if so, yes it is doable
kaileeAuthor Commented:
not exactly.
mes.html is a standard file in each directory.
in mes.html, are words like 'pure' followed by a number, like '08'
so you might find pure 08, planet 03 or factor 04.
also, in each mes.html is the word 'thumb'.
depending on which word (not number) is found, thumb needs to be replaced by that word and its number.

So, I think case - select is needed as part of the script; one for each word.

find . -name mes.html | xargs perl -i -pe '($w,$n)=($1,$2) if /\b(pure|planet|factor)\s*(\d+); s/(thumb)/$w$n/g if $w'

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

a less cryptografic:

list="pure planet factor"
list1=`find . -name mes.html`

for i in $list; do
for j in $list1; do
#check if the work is in this file, hope this is not by a break line separeted
k=`grep $i $j|head -n 1`


for m in $k; do
if [ $m == $i ] ; then
if [ $pass -eq 1 ]; then
sed -e 's/thumb/$l $n/g' $j

kaileeAuthor Commented:
can I use something other than a space in the list?  There are cases where some of the standard words are actually two words, like 'flower power'.
in that case, would you want to replace 'thumb' with 'flower power'?
kaileeAuthor Commented:
I was going to do a search and replace after this process, to keep this one simple.
so, actually, each standard search word (or combo) is replaced by a pair of characters.
So, flower power 12 will become fp12.  mutual ecology 05 will beccome me05.

then would pure 08 become p08?
kaileeAuthor Commented:
yes.  However, I could make it easier by adding a dummy word after the single word ones.  like pure dummy 08, world dummy 13, etc.
can there be more than one standard word(s) in the file?
would they always appear before the corresponding thumbs?
you could reaplace power by "" and the replace flower by flower power.
kaileeAuthor Commented:
Ozo.  No, there is only one entry per file.  Shal I set them to be one word or two words?
perl -i -pe '($w,$x,$n)=($1,$2,$3) if /\b(?=(.).*?\b(\w))(?:flower power|word dummy)\s*(\d+)/; s/(thumb)/$w$x$n/g if $w'
kaileeAuthor Commented:
Sorry, I was out of town for awhile.  I'm back at looking at this and will try these solutions
Hanno P.S.IT Consultant and Infrastructure ArchitectCommented:
No comment has been added to this question in more than 21 days, so it is now classified as abandoned.

I will leave the following recommendation for this question in the Cleanup Zone:
SPLIT POINTS - between _iskywalker_ {http:#18856493} and ozo{http:#18856097}

Any objections should be posted here in the next 4 days. After that time, the question will be closed.
JustUNIX, Experts Exchange Cleanup Volunteer
Forced accept.

EE Admin
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.