Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SED without backup file

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

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.

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?

like image 524
LA_ Avatar asked Aug 25 '14 13:08

LA_


2 Answers

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

sed -i '' -e 's/noreply@\(.*\).example.com/[email protected]/' 
like image 76
Marco de Jongh Avatar answered Nov 07 '22 09:11

Marco de Jongh


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

like image 3
Anonymous Avatar answered Nov 07 '22 10:11

Anonymous