0

I have one file called test1.xml withe the following content:

Hello how are you doing?

And am trying to apply the following sed search and replace:

sed -i 's/Hello //g' test1.xml

And the file remains the same!!!

I am copying the content of that same file to a new file I name test2.xml, apply the same sed and it works, Hello gets removed. Any idea?

I'm on OSX BigSur 11.5.2.

Here are the two files: test1.xml: https://we.tl/t-tX1SMdYQ0A test2.xml: https://we.tl/t-AULhYhZ2K9

When checking both files, it looks like they are different:

od -c test1.xml 
0000000  376 377  \0   H  \0   e  \0   l  \0   l  \0   o  \0      \0   h
0000020   \0   o  \0   w  \0      \0   a  \0   r  \0   e  \0      \0   y
0000040   \0   o  \0   u  \0      \0   d  \0   o  \0   i  \0   n  \0   g
0000060   \0   ?                                                        
0000062


od -c test2.xml
0000000    H   e   l   l   o       h   o   w       a   r   e       y   o
0000020    u       d   o   i   n   g   ?                                
0000030
Milos Cuculovic
  • 423
  • 3
  • 8
  • 22
  • See [Why is sed outputting no text?](//apple.stackexchange.com/q/320501). – Joseph Quinsey Sep 13 '21 at 14:44
  • And perhaps see [Is there an alternative to sed that supports unicode?](//unix.stackexchange.com/q/196780). – Joseph Quinsey Sep 13 '21 at 14:46
  • Also, the macOS (/BSD) version of `sed` parses the `-i` option differently from the Linux (/GNU) version, so you need to use `sed -i '' ...`. See [this question](https://unix.stackexchange.com/questions/92895/how-can-i-achieve-portability-with-sed-i-in-place-editing) and [this one on stackoverflow](https://stackoverflow.com/questions/5694228/sed-in-place-flag-that-works-both-on-mac-bsd-and-linux). – Gordon Davisson Sep 13 '21 at 23:47

0 Answers0