bash 没有备份文件的 SED
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25486667/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
SED without backup file
提问by LA_
I use the following sed
command to replace text in the file:
我使用以下sed
命令替换文件中的文本:
sed -i -e 's/noreply@\(.*\).example.com/[email protected]/' cron.yaml
But it create backup of the file cron.yaml
under name cron.yaml-e
.
但它会cron.yaml
在 name 下创建文件的备份cron.yaml-e
。
I tried to move -i
to the end:
我试图-i
走到最后:
sed -e 's/noreply@\(.*\).example.com/[email protected]/' -i cron.yaml
but in this case sed
returns an error.
但在这种情况下会sed
返回错误。
How should I modify my command line to avoid backup file creation?
我应该如何修改我的命令行以避免创建备份文件?
回答by Marco de Jongh
According to the man pageyou should specify a zero length extension on macOS
根据手册页,您应该在 macOS 上指定零长度扩展
sed -i '' -e 's/noreply@\(.*\).example.com/[email protected]/'
回答by Anonymous
On Windows the GNUWIN32 sed FAILS, when putting any of this:
在 Windows 上,GNUWIN32 sed 失败,当输入以下任何内容时:
sed -i "s/WhatToFind/WhatToPut/g" ".\MyDir\*"
sed -i "s/WhatToFind/WhatToPut/g" ".\MyDir\*"
sed -i.BackUp "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.
备份总是在实际文件夹中创建的,文件名模式为sed$$$$$$
,其中六个 $ 代表随机字母和数字。
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).
并且它还尝试按sub-folders
原样阅读files
,当然会显示impossible to read
此类信息sub-folders
;当然它不会递归子文件夹,它只适用于同一文件夹中的所有内容,但不适用于子文件夹中的内容(非递归)。
In shorts words: -i
is not working at all as spected.
简而言之:-i
根本没有像预期的那样工作。
GNUWIN32 sed version i am using is 4.2.1, it was downloaded from: http://gnuwin32.sourceforge.net/packages/sed.htm
我使用的 GNUWIN32 sed 版本是 4.2.1,它是从以下位置下载的: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
在 Google 上,我找到了一个讨论该 BUG 的网站,并建议下载一个ssed
替代sed
工具,我有点害怕没有official
;链接到我在 Google-i
上发现的关于该BUG 的内容sed
:http: //www.thinkplexx.com/learn/snippet/cmd/one-liner/working-in-place-sed-option-under-windows