-1

I am quite new to Bash and sed.

I have a file named test.xml. This looks like this:

variable1="" variable2="" variable3=""

This is only one line of the file there is more above and under of this line. My goal is that at the end with sed the line looks like this:

variable1="" variable2="123" variable3=""

I tried with this command: sed -i 's/\bvariable2="\b/& 123/' test.xml But this didnt work. Any ideas?

Dario
  • 9
  • Your original pattern doesn't match because `\b` looks for a word boundary (e.g. the boundary between a word character and a non-word character) and there's no such boundary in `""`. If you'd removed the second `\b` it would work. – cmbuckley Jan 05 '22 at 12:16

1 Answers1

0

may be :

sed -i '' 's/variable2=""/variable2="123"/g' test.xml
Eugene
  • 117,005
  • 15
  • 201
  • 306
  • sed -i 's/variable2=""/variable2="123"/g' test.xml worked for me. Thank you very much. – Dario Jan 05 '22 at 12:19
  • It would be good to see an explanation with the answer as the OP did attempt something similar and wasn't able to come to a solution. – Tim Jan 05 '22 at 13:36