SED without backup file

一曲冷凌霜 提交于 2019-12-30 00:30:19

问题


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/noreply@example.com/' -i cron.yaml

but in this case sed returns an error.

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


回答1:


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

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



回答2:


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



来源:https://stackoverflow.com/questions/25486667/sed-without-backup-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!