SED without backup file

MacosBashSedOsx Mavericks

Macos Problem Overview


I use the following sed command to replace text in the file:

sed -i -e 's/noreply@\(.*\).example.com/noreply@example.com/' cron.yaml

But it create backup of the file cron.yaml under name cron.yaml-e.

I tried to move -i to the end:

sed -e 's/noreply@\(.*\).example.com/[email protected]/' -i cron.yaml

but in this case sed returns an error.

How should I modify my command line to avoid backup file creation?

Macos Solutions


Solution 1 - Macos

According to the man page you should specify a zero length extension on macOS

sed -i '' -e 's/noreply@\(.*\).example.com/[email protected]/' 

Solution 2 - Macos

On Windows the GNUWIN32 sed FAILS, when putting any of this:

sed -i "s/WhatToFind/WhatToPut/g" ".\MyDir\*"

sed -i.BackUp "s/WhatToFind/WhatToPut/g" ".\MyDir\*"

The BackUps are allways created on actual folder with a file name pattern of sed$$$$$$, where that six $ represents random leters and numbers.

I see no way for it to not create any BackUP at all, neither to create BackUPs that can be know to which file was the source, neither create backups on the same folder as source file.

And it also tries to read sub-folders as is they where files, of courrse showing an impossible to read message for such sub-folders; and of course it does not recurse sub-folders, it only works with all on the same folder, but not with what is on sub-folders (not recursive).

In shorts words: -i is not working at all as spected.

GNUWIN32 sed version i am using is 4.2.1, it was downloaded from: http://gnuwin32.sourceforge.net/packages/sed.htm

On Google i found a web that talks about that BUG and remomends to download a ssed instead to sed tool, i am a little afraid of not being official; link to what i found on Google about that -i BUG on sed: http://www.thinkplexx.com/learn/snippet/cmd/one-liner/working-in-place-sed-option-under-windows

Solution 3 - Macos

Windows workaround

The accepted answer does not work for the GNUWin32 sed. I tried several variants (-i '', -i - like @Anonymous says), but it still created some backup file.

Easiest workarounds for me were to use:

  1. sed that comes with Git for Windows
  2. sed inside WSL shell.

Both worked perfectly.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionLA_View Question on Stackoverflow
Solution 1 - MacosMarco de JonghView Answer on Stackoverflow
Solution 2 - MacosAnonymousView Answer on Stackoverflow
Solution 3 - Macosm01010011View Answer on Stackoverflow