Skip to main content
Minor rewording on explanation
Source Link
AdminBee
  • 23.6k
  • 25
  • 55
  • 77
sed -i -E "s/(<username>.+)name(.+<\/username>)/\1something\2/" file.xml 

This is, I think, what you're looking for.

Explanation:

  • parentheses in the first part define groups (strings in fact) that can be reused in the second part
  • \1, \2, etc. in the second part are references to the i-th group captured in the first part (the numbering starts with 1)
  • -E enables extended regular expressions (needed for + and grouping).
  • -i enables edit"in-place" file in placeedit mode
sed -i -E "s/(<username>.+)name(.+<\/username>)/\1something\2/" file.xml 

This is, I think, what you're looking for.

Explanation:

  • parentheses in the first part define groups (strings in fact) that can be reused in the second part
  • \1, \2, etc. in the second part are references to the i-th group captured in the first part (the numbering starts with 1)
  • -E enables extended regular expressions (needed for + and grouping).
  • -i enables edit file in place mode
sed -i -E "s/(<username>.+)name(.+<\/username>)/\1something\2/" file.xml 

This is, I think, what you're looking for.

Explanation:

  • parentheses in the first part define groups (strings in fact) that can be reused in the second part
  • \1, \2, etc. in the second part are references to the i-th group captured in the first part (the numbering starts with 1)
  • -E enables extended regular expressions (needed for + and grouping).
  • -i enables "in-place" file edit mode
sed -i -E "s/(<username>.+)name(.+<\/username>)/\1something\2/" file.xml 

This is, I think, what you're looking for.

Explanation:

  • parentheses in the first part define groups (strings in fact) that can be reused in the second part
  • \1, \2, etc. in the second part are references to the i-th group captured in the first part (the numbering starts with 1)
  • -E enables extended regular expressions (needed for + and grouping).
  • -i enables edit file in place mode
sed -i -E "s/(<username>.+)name(.+<\/username>)/\1something\2/" file.xml 

This is, I think, what you're looking for.

Explanation:

  • parentheses in the first part define groups (strings in fact) that can be reused in the second part
  • \1, \2, etc. in the second part are references to the i-th group captured in the first part (the numbering starts with 1)
  • -E enables extended regular expressions (needed for + and grouping).
sed -i -E "s/(<username>.+)name(.+<\/username>)/\1something\2/" file.xml 

This is, I think, what you're looking for.

Explanation:

  • parentheses in the first part define groups (strings in fact) that can be reused in the second part
  • \1, \2, etc. in the second part are references to the i-th group captured in the first part (the numbering starts with 1)
  • -E enables extended regular expressions (needed for + and grouping).
  • -i enables edit file in place mode
deleted 4 characters in body
Source Link
lgeorget
  • 14.4k
  • 2
  • 44
  • 64
sed -i -E "s/(<username>.+)name(.+<\/username>)/\1something\2/" file.xml 

This is, I think, what you're looking for.

Explanation:

  • parentheses in the first part define groups (strings in fact) that can be reused in the the second part
  • \1, \2, etc. in the second part are references to the i-th group captured in the first part (the numbering starts with 1)
  • -E enables extended regular expressions (needed for + and grouping).
sed -i -E "s/(<username>.+)name(.+<\/username>)/\1something\2/" file.xml 

This is, I think, what you're looking for.

Explanation:

  • parentheses in the first part define groups (strings in fact) that can be reused in the the second part
  • \1, \2, etc. in the second part are references to the i-th group captured in the first part (the numbering starts with 1)
  • -E enables extended regular expressions (needed for + and grouping).
sed -i -E "s/(<username>.+)name(.+<\/username>)/\1something\2/" file.xml 

This is, I think, what you're looking for.

Explanation:

  • parentheses in the first part define groups (strings in fact) that can be reused in the second part
  • \1, \2, etc. in the second part are references to the i-th group captured in the first part (the numbering starts with 1)
  • -E enables extended regular expressions (needed for + and grouping).
deleted 2 characters in body
Source Link
phk
  • 6.1k
  • 7
  • 44
  • 76
Loading
Source Link
lgeorget
  • 14.4k
  • 2
  • 44
  • 64
Loading