Reputation: 129
I have some file in which I need to change the logging level and trying to use sed
<asyncLogger name="blabla" additivity="true" level="info" includeLocation="true">
</asyncLogger>
<asyncLogger name="blabla1" additivity="true" level="fine">
I tired this command but it cuts down the end of the line.
sed 's/\(level="\).*/"\1\debug\"/' file.xml
I am trying to fine level="wildcard" and replace it with level="debug" and the rest of the line
Upvotes: 1
Views: 272
Reputation: 104024
It is almost never a good idea to modify xml with sed
...
That said, your issue is the .*
since it is greedy. It sucks up the remainder of the line.
You can do:
$ sed -E 's/(level=")[^"]*/\1debug/' file
<asyncLogger name="blabla" additivity="true" level="debug" includeLocation="true">
</asyncLogger>
<asyncLogger name="blabla1" additivity="true" level="debug">
Upvotes: 2
Reputation: 22402
Something like this should replace level="blah"
with level="debug"
sed -e 's/level="[^"]"/level="debug"/g' file.xml
Upvotes: 0
Reputation: 3776
You need to make the regular expression less greedy as your .* eats everything to the end of the line.
sed -r -e 's/(\<level *= *)["a-zA-Z"]+/\1"debug"/g'
Upvotes: 0