0
votes

I have a list of 300+ files that have to be edited, so i thought that sed command in tandem with find and exec could help me.

Before doing something wrong (like overwrite files that I won't modify, or something like that) I decided to use sed and output his result into bash instead local substitution.

The string i'm searchin' for is: <tr><td class="button" style=" background:#040404; color:#eee9dc; font-size: 23px; padding:5px 0; text-align:center;"><a href="../Z2/C24357-0/hhcm-LASTMINUTES.html" style=" text-decoration:none; cursor:pointer; color:#eee9dc">Offerte & LastMinute</a></td></tr>

and I only want to replace that part <a href="../Z2/C24357-0/hhcm-LASTMINUTES.html with <a href="../../../special_offers.php?lang=it"

Since I'm a noob about regex , i'll take a look at that web page that drive me into regex argument in a decent way.

Now, i've try something like that (on a single file, just for take a look to the output in a "safe" way)

 sed s/\<a.*LAST.*html\"
      /\<a href="\.\.\/\.\.\/\.\.\/special_offers\.php\?lang=en"/ 
      C25030-9_3/hhcm-Solo_per_due.html

and I get that error: sed: -e expression #1, char 20: unterminated s' command like the sed expressions isn't correct, but I don't know if the error is into the replacement part or somewhere else.

Thanks from now for your time and effort.

S.

Edit

Thanks to answers, I resolved it by doin' something this

sed 's/<a.*LAST.*html\"/\<a href="..\/..\/..\/special_offers.php?lang=en"/' C25030-9_3/hhcm-Solo_per_due.html
1

1 Answers

1
votes

First, it seems that you need to put the whole sed expression (s/.../.../) in single quotes, second, you forgot the / in the end (see edit), and third, don't forget that the substitution will only work if the whole pattern string is on one line.

EDIT: More info on s command (see here, for example): it's s/old/new/ and possible flags after the last /. Your command looks like s/something/somethingelse/somethingelse, it has more than it should, I think.