Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR SHELL

Using sed to find and replace complex string (preferrably with regex)

sed -i -E "s/(<username>.+)name(.+</username>)/1something2/" 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
Source by unix.stackexchange.com #
 
PREVIOUS NEXT
Tagged: #Using #sed #find #replace #complex #string
ADD COMMENT
Topic
Name
1+5 =