BASH: sed command

I’m trying to replace a copyright token true sed in a *.html file

source → Wandelkaart Kaartgegevens © OpenStreetMap
target → Wandelkaart Kaartgegevens © OpenStreetMap-auteurs

the code that i’m using, but no luck, is:



sed -i s/©/©/g "target.html"


what can we do to replace exact to “©” ?

heelstraf wrote:
>
> I’m trying to replace a copyright token true sed in a *.html file
>
> source → Wandelkaart Kaartgegevens © OpenStreetMap
> target → Wandelkaart Kaartgegevens © OpenStreetMap-auteurs
>
> the code that i’m using, but no luck, is:
>
> Code:
> --------------------
>
>
> sed -i s/©/©/g “target.html”
>
>
> --------------------
>
>
> what can we do to replace exact to “©” ?
>
>
try

sed -i s/"©"/"\&copy\;"/g "target.html"


GNOME 3.10.1
openSUSE 13.1 (Bottle) (x86_64) 64-bit
Kernel Linux 3.11.6-4-desktop

Please do explain this more extensive. “no luck” is a very bad description on what happened. Was the file the same after you did this, was there anything changed and when yes, what was changed. Do not let us guess, but tell us.

And yes, the & in a replacement string has a special meaning. From the man page:

s/regexp/replacement/
Attempt to match regexp against the pattern space. If successful, replace that portion matched with replacement. The replacement may contain the special character & to refer to that portion of the pattern space which matched, and the special escapes \1 through \9 to refer to the corresponding matching sub-expressions in the regexp.

With this code it doesn’t do what i want, what happens if i run sed
source → Wandelkaart Kaartgegevens © OpenStreetMap
target → Wandelkaart Kaartgegevens © OpenStreetMap-auteurs
If i open it with kwrite it displays the sigh OK, but not in firefox

Note that i want to display copyright sign in html file
the html-code in for © is code “©”

First you should be aware of the fact that the character encoding of the file can be different from what you think. Then different programs can also have different ideas about that encoding. When you say FF, are you loading that file then through a web-server? Then it depends on what the server says the encoding is and/or meta statements about this in the HTML header.

Idealy all is in UTF-8. But I do not know where you have that file from. The fact that it displays things like  lets us assume that a wrong encoding assumption is already there.

You can try to use vi on it and then type :set as command. It will show what vi thinks it is (attention: vi is also doing only a intelligent guess and can be wrong).

BTW when the file is in UTF-8 and is served as such by the web server, there is no need to use the &…; construct. Putting the © in the file is then OK (as you can see here, I did not use a &…; ).

This is the best solution :wink:
no need for using command sed

changed the html file like that:

<head>
    <title>Reizen</title>
    <META HTTP-EQUIV="content-type" CONTENT="text/html; charset=UTF-8">
    <link rel=stylesheet type="text/css" href="../../stylesheet.css">
    <link rel="shortcut icon" href="../../img/button/pm.ico">
</head>

instead of using “charset=iso-8859-1”

the question of sed command started to make my script/servicemenu better
I can easy make a html file of a few photo’s, had problem with copyright sign.

movie:
[video]http://users.telenet.be/photo-memories/img/service_voor_web_reizen.mpg[/video]

script:
SUSE Paste

The change is OK. But, assuming you have Apache running for this (maybe I am wrong here, because you did not realy explain that), also check if Apache has in /etc/apache2/default-server.conf:

AddDefaultCharset utf-8

The correct characterencosing should already be in the HTTP protocol lines send to the client. The one inside the HTML page is at the maximum additional.

EDIT: leuk filmpje