Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: possible to change st in the source code of html via SSH?  (Read 4175 times)

0 Members and 1 Guest are viewing this topic.

doncamillo

    Topic Starter


    Greenhorn

    possible to change st in the source code of html via SSH?
    « on: April 28, 2008, 06:46:55 AM »
    I wonder if it is possible a mass changing in the source codes of all htm or php files via unix command from SSH.

    For example in the home directory, search a html code such as (charset="ISO-8859-1")
     in soruces of all html files (*.html) and change it  (charset="ISO-1245-1")







    ghostdog74



      Specialist

      Thanked: 27
      Re: possible to change st in the source code of html via SSH?
      « Reply #1 on: April 28, 2008, 07:03:54 PM »
      Code: [Select]
      sed -i "s/ISO-8859-1/ISO-1245-1/g" *html

      doncamillo

        Topic Starter


        Greenhorn

        Re: possible to change st in the source code of html via SSH?
        « Reply #2 on: April 29, 2008, 02:51:17 AM »
        1. First of all, incase of a mistake, how can i list the files that will be changed with sed command. I mean firstly i want to see(list) the files which have the "ISO-8859-1" in their source codes. like find command.


        2. what if i want to change a long code which already includes "/" charcater in it. Will it be a problem?

        For example


        Code: [Select]
        <link rel="stylesheet" type="text/css" href="http://www.computerhope.com/forum/Themes/classic/style.css?fin11" />
        replace with
        Code: [Select]
        <link rel="stylesheet" type="text/css" href="http://www.test.com/test/test/test.css?fin22" />
        3. if i want to erase whole code can i add a space?
        Such as

        Code: [Select]
        sed -i "s/ISO-8859-1/ /g" *html
        « Last Edit: April 29, 2008, 06:07:07 AM by doncamillo »

        KenJackson



          Beginner
        • Thanked: 1
          • Yes
          • Jackson I/O
        • Experience: Experienced
        • OS: Linux variant
        Re: possible to change st in the source code of html via SSH?
        « Reply #3 on: May 05, 2008, 04:03:07 PM »
        1. First of all, incase of a mistake, how can i list the files that will be changed with sed command. I mean firstly i want to see(list) the files which have the "ISO-8859-1" in their source codes. like find command.

        You can simply use grep to see which files have that text in them.

        Alternately, you can replace the -i switch in the suggested command with -i.bak to create a backup file.  Then use diff to compare the original and backup file, if wanted, and delete the backup file when you're confident.

        Quote
        2. what if i want to change a long code which already includes "/" charcater in it. Will it be a problem?

        The sed 's' command can use almost any character instead of '/'.  This incomplete example will do part of what you want:
        Code: [Select]
        sed -i.bak "s,computerhope.com/forum/,test.com/test/," *html
        Quote
        3. if i want to erase whole code can i add a space?
        Such as

        Code: [Select]
        sed -i "s/ISO-8859-1/ /g" *html

        Yes, that will work.  You don't even need a space -- just put two slashes together.

        Note that it's often helpful to experiment with sed on the command line:
        Code: [Select]
        echo "abcde" | sed 's,bcd,,'