Find the answer to your Linux question:
Results 1 to 2 of 2
Hello, 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 ...
  1. #1
    Just Joined!
    Join Date
    Jul 2004
    Posts
    24

    Help w/ sed parsing special characters

    Hello,

    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/http://cache.somewebsite.com/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. #2
    Trusted Penguin Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,230
    The problem with your sed command is that in sed, the '/' character indicates the delimiter of the sections. If you want to use '/' inside the pattern or replacement, you need to escape it, so that your line looks like:
    Code:
    sed -e 's/images/http:\/\/cache.somewebsite.com\/images' ajax_scaffold.css
    (that is, every '/' preceded by a '\')

    As for doing it to every file in a directory, just do:
    Code:
    sed -e 'PATTERN' directory/*
    The /* means "all files inside the directory".
    DISTRO=Arch
    Registered Linux User #388732

Posting Permissions

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