-1

I have some XML files in a directory and they all include the tag: <difficult>0</difficult>. I just want to change that to <difficult>1</difficult>.

I'm using the following command:

sed 's/difficult>0/difficult>1/g' *.xml

All that happens is that the full XML text of all the files gets displayed, with the difficult tag showing a value of 1, but nothing happens to the actual files. When I open them, they still all contain <difficult>0</difficult>.

user961627
  • 12,379
  • 42
  • 136
  • 210
  • 1
    possible duplicate of [Change a string in a file with sed?](http://stackoverflow.com/questions/10919554/change-a-string-in-a-file-with-sed) – tripleee Jan 22 '15 at 17:28
  • possible duplicate of [Bash, Remove empty XML tags](http://stackoverflow.com/questions/26735715/bash-remove-empty-xml-tags) – NeronLeVelu Jan 23 '15 at 12:59

3 Answers3

1

Yes, sed usually puts its result on stdout. To change the files in-place, use the -i flag:

  -i[SUFFIX], --in-place[=SUFFIX]

          edit files in place (makes backup if SUFFIX supplied)
Ulrich Schwarz
  • 7,598
  • 1
  • 36
  • 48
1

One more time :)

Don't use regex to parse HTML. Using a proper parser & :

xml ed -L -u '//difficult/text()' -v "1" file

xml is

Check: RegEx match open tags except XHTML self-contained tags

Community
  • 1
  • 1
Gilles Quénot
  • 173,512
  • 41
  • 224
  • 223
1
sed -i 's/difficult>0/difficult>1/g' *.xml

Change a string in a file with sed?

kittykittybangbang
  • 2,380
  • 4
  • 16
  • 27
  • You don't have the privileges for nominating duplicates yet, but in general, if you fInd a duplicate, please leave a comment with a link instead of answering. Thanks. – tripleee Jan 22 '15 at 17:30