#1
  1. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Posts
    701
    Rep Power
    96

    Sed to edit part of text file


    I have thousands of html files and I want issue a command to change
    <img src="../images/school.gif" width="105" height="94" border="0" alt="" align="middle">
    to
    <replace>
    Can you suggest a solution?
    Evan
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2006
    Posts
    2,481
    Rep Power
    1752
    I'm tired so likely to get something a bit wrong so make sure you have backups!

    Code:
    sed -ibak -e 's/\<img src=\"\.\.\/images\/school\.gif\" width\=\"105\" height\=\"94\" border\=\"0\" alt\=\"\" align\=\"middle\"\>/\<replace\>/' *.html

    Comments on this post

    • epanagio agrees : Bingo!
    The moon on the one hand, the dawn on the other:
    The moon is my sister, the dawn is my brother.
    The moon on my left and the dawn on my right.
    My brother, good morning: my sister, good night.
    -- Hilaire Belloc
  4. #3
  5. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Posts
    701
    Rep Power
    96
    Even when you are tired you do things right.
    I took your string and modified it in order to get the correct information instead of <replace>. To be safe I escaped all non alphanumeric characters and it worked like a charm.

    Thanks!
    Evan
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2006
    Posts
    2,481
    Rep Power
    1752
    Yeah, I probably ovver-egged the pudding on the quoting, but glad it worked
    The moon on the one hand, the dawn on the other:
    The moon is my sister, the dawn is my brother.
    The moon on my left and the dawn on my right.
    My brother, good morning: my sister, good night.
    -- Hilaire Belloc

IMN logo majestic logo threadwatch logo seochat tools logo