Results 1 to 8 of 8

Thread: BASH: sed command

  1. #1
    Join Date
    Jul 2012
    Location
    Belgium
    Posts
    215

    Default 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:
    Code:
    sed -i s/©/©/g "target.html"
    what can we do to replace exact to "©" ?

  2. #2
    Join Date
    May 2010
    Location
    Space Colony Lagrange Point 22° à, 77° Ƅ, 56° ɤ, 99° ɜ
    Posts
    3,166

    Default Re: BASH: sed command

    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
    Code:
    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

  3. #3
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    29,773

    Default Re: BASH: sed command

    Quote Originally Posted by heelstraf View Post
    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 "©" ?
    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.
    Henk van Velden

  4. #4
    Join Date
    Jul 2012
    Location
    Belgium
    Posts
    215

    Default Re: BASH: sed command

    Quote Originally Posted by vazhavandan View Post
    try
    Code:
    sed -i s/"©"/"\&copy\;"/g "target.html"
    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 "©"

  5. #5
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    29,773

    Default Re: BASH: sed command

    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 &...; ).
    Henk van Velden

  6. #6
    Join Date
    Jul 2012
    Location
    Belgium
    Posts
    215

    Default Re: BASH: sed command

    Quote Originally Posted by hcvv View Post
    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 ;-)
    no need for using command sed

    changed the html file like that:
    Code:
    <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"

  7. #7
    Join Date
    Jul 2012
    Location
    Belgium
    Posts
    215

    Default Re: BASH: sed command

    Quote Originally Posted by heelstraf View Post
    This is the best solution ;-)
    no need for using command sed

    changed the html file like that:
    Code:
    <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:
    http://users.telenet.be/photo-memori...web_reizen.mpg

    script:
    SUSE Paste

  8. #8
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    29,773

    Default Re: BASH: sed command

    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:
    Code:
    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
    Last edited by hcvv; 29-Nov-2013 at 10:31.
    Henk van Velden

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •