question for the sed experts - Unix

This is a discussion on question for the sed experts - Unix ; Hello sed experts, my original line looks like this: Location file://localhost/d:/My%20Music/mp3/311/From%20Chaos/10%20Amber.mp3 and shall be modified to look like this: Location file://localhost/d:/My%20Music/mp3/10%20Amber.mp3 I am stumped. Can someone help me find the right sed-command? Any help greatly appreciated! Joh....

+ Reply to Thread
Results 1 to 5 of 5

Thread: question for the sed experts

  1. question for the sed experts

    Hello sed experts,

    my original line looks like this:

    Locationfile://localhost/d:/My%20Music/mp3/311/From%20Chaos/10%20Amber.mp3

    and shall be modified to look like this:

    Locationfile://localhost/d:/My%20Music/mp3/10%20Amber.mp3

    I am stumped. Can someone help me find the right sed-command?

    Any help greatly appreciated!

    Joh.

  2. Re: question for the sed experts

    Johann Siebers wrote:
    > Hello sed experts,
    >
    > my original line looks like this:
    >
    > Locationfile://localhost/d:/My%20Music/mp3/311/From%20Chaos/10%20Amber.mp3
    >
    > and shall be modified to look like this:
    >
    > Locationfile://localhost/d:/My%20Music/mp3/10%20Amber.mp3
    >
    > I am stumped. Can someone help me find the right sed-command?
    >
    > Any help greatly appreciated!
    >
    > Joh.


    sed 's?311/From%20Chaos/??'

    Ed.

  3. Re: question for the sed experts

    Finally found a solution:

    sed 's/\(^.*Location.*\)\/mp3\/.*\(\/\{1,1\}[^/]*\/string.*\)/\1\/mp3\2/'

    Thanks for trying anyway!

  4. Re: question for the sed experts

    Johann Siebers wrote:
    > Finally found a solution:
    >
    > sed 's/\(^.*Location.*\)\/mp3\/.*\(\/\{1,1\}[^/]*\/string.*\)/\1\/mp3\2/'
    >
    > Thanks for trying anyway!


    Your expression does not work with all sed versions, and can be simplified to

    sed 's?^\(.*Location.*/mp3\)/.*\(/[^/]*/string.*\)?\1\2?'


    --
    Michael Tosch @ hp : com

  5. Re: question for the sed experts

    In article eobsf9$vc$1@aioe.org, dated Sun, 14 Jan 2007 01:11:19 +0100,
    Johann Siebers wrote:

    > Finally found a solution:
    >
    > sed
    > 's/\(^.*Location.*\)\/mp3\/.*\(\/\{1,1\}[^/]*\/string.*\)/\1\/mp3\2/'
    >
    > Thanks for trying anyway!


    This is overkill, and needlessly complex.

    Do be aware that you don't necessarily *have* to use "/" as the delimiter
    character in sed expressions, just as long as you're consistent as far as
    whatever delimiter you choose, i.e., be sure to use the same delimiter
    throughout the expression.

    When I write sed expressions that operate on pathnames including slashes,
    I generally use "#" as the delimiter to avoid the need to escape each and
    every occurrence of the "/" character within the expression.

    It looks like all you want to do is simply chop out the section containing
    "/311/From%20Chaos" from the original line, correct? As such, one
    solution might be:

    sed -e 's#/311/From%20Chaos##'

    Simple, no? :-)

    --
    Conrad J. Sabatier
    "In Unix veritas"

+ Reply to Thread