Results 1 to 3 of 3

Thread: SED - replace all text after a matched string

  1. #1
    Join Date
    Oct 2006
    Beans
    607

    SED - replace all text after a matched string

    Hello

    Im looking to replace text after "MapLocation=" and the add a file path eg MapLocation=/mnt1/acc/config

    The reason I cant do a simple sed replace, is that path MapLocation=build_snapshot0.1.0/build
    has a number that will increment as i get new snapshot from the developers - so there isn't a static string to replace
    I have tried the folling with no luck
    Code:
    egrep -i build_snapshot | xargs -0 sed -i 's|build_snapshot|/mnt1/acc/config|g'
    If I do a simple sed replace it still has 0.1.0/build at the end
    Code:
    's|build_snapshot|/mnt1/acc/config|g'
    resulting /mnt/acc/config/0.1.0/build
    I need the final result to be

    MapLocation=/mnt1/acc/config
    Regardless of version numbers

    Please can you help

  2. #2
    Join Date
    Apr 2012
    Beans
    7,256

    Re: SED - replace all text after a matched string

    maybe you could add [.0-9]\+ to match any combination of periods and digits?

    Code:
    echo "MapLocation=build_snapshot0.1.0/build" | sed 's|build_snapshot[.0-9]\+/build|/mnt1/acc/config|'
    MapLocation=/mnt1/acc/config

  3. #3
    Join Date
    Oct 2006
    Beans
    607

    Re: SED - replace all text after a matched string

    Many thanks - that fixed the issue

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
  •