Score:0

sed behaviour depending on the file I apply it to

jp flag

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
Joseph Quinsey avatar
ng flag
See [Why is sed outputting no text?](//apple.stackexchange.com/q/320501).
Joseph Quinsey avatar
ng flag
And perhaps see [Is there an alternative to sed that supports unicode?](//unix.stackexchange.com/q/196780).
ph flag
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).
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.