Page 2 of 2 FirstFirst 12
Results 11 to 14 of 14

Thread: Batch replace strings in all files in a folder--when there are UNIX-style slashes

  1. #11
    Join Date
    Dec 2006
    Beans
    Hidden!

    Re: Batch replace strings in all files in a folder--when there are UNIX-style slashes

    Quote Originally Posted by tarahmarie View Post
    Here's my output when I try that:

    Code:
    /data/Music/testplay Hello! $sed -i 's/\\home/tarahmarie/Music\\/\\data/Music\\/g'
    sed: -e expression #1, char 22: unknown option to `s'
    Lol, what the heck are you doing?!

    The answer has been given already (post #4).
    Code:
    sed -i 's/home\/tarahmarie/data/g' file.m3u
    
    sed -i 's|home/tarahmarie|data|g' file.m3u
    Think about it:
    Code:
    sed        # program
    -i         # edit the same file
    '     '    # single quotes prevent expansions by the shell
    s          # replace
    
    /old/new/
    |old|new|  # the separators can be any character
    +old+new+  # since the old string already contains a slash (/),
    ?old?new?  # use a different character
    .old.new.  # etc.
    
    g          # multiple replaces
    file.m3u   # name of the file to operate on

  2. #12
    Join Date
    Sep 2008
    Beans
    540
    Distro
    Kubuntu 12.04 Precise Pangolin

    Re: Batch replace strings in all files in a folder--when there are UNIX-style slashes

    The problem was that I didn't understand that I was acting on files; my buddy offline actually gave me the correct answer, which was to append an asterix on the end so all file types were altered. I had m3u and xml playlists in the same directory.

    I ended up using % as a delimiter; it jumps out at the eye a little more.

    Thanks, all!
    Registered Linux User #479009
    Friend-->Linux; 6 and counting...

  3. #13
    Join Date
    Aug 2007
    Beans
    949

    Re: Batch replace strings in all files in a folder--when there are UNIX-style slashes

    So in other words you did this (in the appropriate directory)?

    Code:
    sed -i 's%home/tarahmarie%data%g' *

  4. #14
    Join Date
    Sep 2008
    Beans
    540
    Distro
    Kubuntu 12.04 Precise Pangolin

    Re: Batch replace strings in all files in a folder--when there are UNIX-style slashes

    Quote Originally Posted by soltanis View Post
    So in other words you did this (in the appropriate directory)?

    Code:
    sed -i 's%home/tarahmarie%data%g' *
    Yep, though I added the Music subfolder as well to make sure all the correct strings were replaced.
    Registered Linux User #479009
    Friend-->Linux; 6 and counting...

Page 2 of 2 FirstFirst 12

Tags for this Thread

Bookmarks

Posting Permissions

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