SED 4.2 --in-place - Broken (Again)
Provides native Win32 open source ports and utilities
Brought to you by:
gnuwin32
The --in-place switch is broken (again).
It works fine in SED 4.1.4, 4.1.5 but 4.2 is broken. I reported this same problem with a previous ported GnuWin32 version of SED a few years back. Search for it.
Error:
sed.exe: cannot rename ./sedv4PHwv: File exists
Example:
sed.exe --in-place --regexp-extended --unbuffered --expression="/^[[:space:]][/ h; /^[[:space:]]%~3[[:space:]]=/I { x; /^[[:space:]][[[:space:]]%~2[[:space:]]]/I { x; s/^([[:space:]]%~3[[:space:]]=[[:space:]])(.)[[:space:]]*$/\1%~4/I; x; }; x; };" "%filePath%"
The new SED 4.2-1 update removes the --in-place option completely! Please fix the problem like you did in a previous SED release, but do not remove this option.
sed.exe: unrecognized option `--in-place'
For example:
sed --in-place -e s/a/b/ aaa
where aaa contains some lines, works for me.
Could you create an example that doesn't work and post an exact copy of your command line and its results?
Disregard the previous comment about the missing "--in-place" option, had a old SED 3.02 release in a folder in my PATH.
The 4.2-1 release works with the --in-place switch but it leaves the temporary file behind without deleting it inside the Working Folder for the batch file, and not where the source file is located.
Command: sed.exe --in-place --regexp-extended --unbuffered --expression="%~2" "%filePath%"
Here is an example script to use to reproduce this bug.
@ echo off
echo + Create "test.txt" file...
echo search> "test.txt"
echo * Replace "search" with "replace" in "test.txt"...
sed.exe --in-place --regexp-extended --unbuffered --expression="s/search/replace/" "test.txt"
echo ? Check if "sed." temporary file still exists...
if exist "sed." echo - Failed. Bug: The temporary file still exists...
if not exist "sed*." echo + Success. No temporary files found.
echo ? Query sed version...
sed.exe --version | sed.exe --regexp-extended --unbuffered --quiet --expression="1 p;"
For reference, I'm running Windows XP SP3.
I'm experiencing the same problem, too: when using option "-i" or "--in-place", sed leaves behind a temporary file of pattern "sed??????".
This is a slightly modified batch file derived from jakfrost's version which reproduce the problem. It creates a sed_test.txt file and runs sed over it using option "-i". Then, it checks whether a temporary file of pattern "sed??????" is left behind in the same directory where sed was run from.
@echo off
echo + Create "sed_test.txt" file...
echo foo> sed_test.txt
echo * Replace "foo" with "bar" in sed_test.txt...
sed.exe -i -e "s/foo/bar/" sed_test.txt
echo ? Check if "sed??????" temporary file still exists...
if exist "sed??????" echo - Failed: the temporary file still exists!
if not exist "sed??????" echo + Success. No temporary files found.
echo ? Query sed version...
sed.exe --version | sed.exe -ne "1p"
Like lolo75, I'm also finding that using -i or --in-place leaves the temporary files behind. I noticed that the GnuWin32 version of sed adds the following three lines to the options handling for "-i" in sed.c:
ifdef _WIN32
endif / _WIN32 /
Why was this necessary? The ck_rename() function has WIN32 specific code in it already; does it not work? Shouldn't sed clean up after itself?
This bug has been fixed. A new release is available through
http://gnuwin32.sourceforge.net/
Thanks for reporting the bug.
View and moderate all "bugs Discussion" comments posted by this user
Mark all as spam, and block user from posting to "Bugs"
Hi guys,
I don't understand here, I see on http://gnuwin32.sourceforge.net/ :
which the exact same date as the one of the comment above.
I downloaded GnuWin32 recently and I'm running into the exact same problem although I do have the latest version:
I've also run a script similar to the ones above:
And I got:
I'm running Windows 7 64 bit. (But scripts certainly run in 32 bit WoW emulation.)
Any information advice or workaround would be greatly appreciated!
Regards,
Patryk S.
Last edit: Anonymous 2018-10-19
View and moderate all "bugs Discussion" comments posted by this user
Mark all as spam, and block user from posting to "Bugs"
If somebody else is experiencing the bug, and in a hurry, I recommend the following workaround a batch script to be invoked through
Create a temporary directory and set it as a working directory. Invoke SED, restore original working directory and delete all the temporary files.
See an example implementation at https://gist.github.com/Pinault/4756362
-- The scripts minimal content, in my case is:
(You just need to edit the path to your SED executable)
Regards,
P.
-- WARNING: Please note that if the permissions on your current working directory are specific, going through a temporary file is likely to break the permissions set on that file. In that case it is better to rename the original file, process it and redirect the output of sed in the original working directory in place of the original file (optional: delete the original that was renamed).
Last edit: Anonymous 2018-10-12