Find the answer to your Linux question:
Results 1 to 2 of 2

Thread: regex and sed

Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined! jdh239's Avatar
    Join Date
    Sep 2006
    Posts
    92

    regex and sed


    I haven't used regex with sed before. I have a syntax issue, but don't know how to correct it. Consider the following:
    https://regex101.com/r/EF2OLR/1

    If I have a variable that contains the string:
    Code:
    mac=00:21:f6:04:16:f3bridge=101498d8ff
    I want to manipulate 04:16:f3

    I have the following:
    Code:
    echo $i | sed -e 's|(mac=00:21:f6:)((\w{2}:?){3})(bridge=\w+)|\1MYSTUFF\4|g'
    I am trying to use backrefs (unsuccessfully). I am sure I have a syntax issue, but don't know how to correct it.

    Code:
    sed: -e expression #1, char 57: invalid reference \4 on `s' command's RHS
    sed: -e expression #1, char 57: invalid reference \4 on `s' command's RHS

  2. #2
    Just Joined! jdh239's Avatar
    Join Date
    Sep 2006
    Posts
    92
    -->
    Got it.... needed sed -E, not sed -e

Posting Permissions

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