Help w/ sed parsing special characters

Discussion in 'Programming/Scripts' started by clem_c_rock, Aug 31, 2007.

  1. clem_c_rock

    clem_c_rock New Member


    I'm trying to change the image paths in a directory of files.

    My first question is that I'm trying to use this line to test the change in one file:

    sed -e 's/images/' ajax_scaffold.css

    When I try that I get this:

    sed: 1: "s/images/http://cache.r ...": bad flag in substitute command: '/'

    I did a test by running this:

    sed -e 's/images/duh/' ajax_scaffold.css

    and the output said the changes had worked but when I went to the actual file, the changes didn't show?

    Also, when I find a command that works, is it possible to specify a directory

    and run this command on every file w/in the directory?
  2. ghostdog74

    ghostdog74 New Member

    you escape the slashes...
    sed -e "s/images/http:\/\/\/images/" file
  3. clem_c_rock

    clem_c_rock New Member

    hello, and thanks for your help.

    this is the solution that worked for me:

    for file in *; do
        sed -e 's/\/images/http:\/\/cache\.reverbnation\.com\/images/g' "$file" > "${file}.sub"
        rm "$file"
        mv "${file}.sub" "${file}"

Share This Page