Hi all,

Can anyone shed some light as to why this is not working?

for i in `cat wordlist.txt | dos2unix | sed -e 's/ *$//'`
do
sed -e 's@$i@<a href=http://www.domain.com>$i</a>@g' article.txt
done

I've also tried:

perl -pi -e 's@$i@<a href=http://www.domain.com>$i</a>@g' $file

The worlist.txt file consist of words one line at a time:

word1
word2
word3

The article file consist of ...well one file with 50 articles all apended to each other.

Thanks for any help! :confused:

This would work better.

cat wordlist.txt | tr -d '\r' | while read i ; do
    sed "s-$i-<a href=http://www.domain.com>$i</a>-g" article.txt
 done

But I think what you really want is to put the substitution commands in the wordlist like this:

s-Word1-<a href=http://www.domain.com/Link1>Word1</a>-g
s-Word1-<a href=http://www.domain.com/Link2>Word2</a>-g
s-Word1-<a href=http://www.domain.com/Link3>Word3</a>-g

And then:

sed -f wordlist.txt article.txt > article.html
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.