0

I use sed on Windows (actually under GitBash) and this approach doesn't work.

$ sed -ibak 's/a/b/g' test1
sed: preserving permissions for `./sed004224': Permission denied

Is there any another approach to do this (or maybe fix this)?
(I know about using perl, and we can move a result file to replace source one.)

UPD 1 It works when I run GitBush "as Administrator". Actually logged Windows user is Admin too.

Community
  • 1
  • 1
Kirby
  • 2,847
  • 2
  • 32
  • 42
  • It's the same behavior. ;) – Kirby Jun 09 '15 at 16:11
  • 1
    try this seq 10 | sed 's/$/ Love/' to see is sed problem or test1 permissions – josifoski Jun 09 '15 at 16:13
  • What does `seq` mean? But.. Yeah, this command exists in unix. You know, I don't have it on Windows. And there ain't specific permissions. I suppose there is a permission problem because process and file system. – Kirby Jun 09 '15 at 16:18
  • seq 10 will print nums 1..10 – josifoski Jun 09 '15 at 16:20
  • Is the permissions problem with the sed command or with the test1 file? I would not use the -i option to "edit in place". If the script fails your input file is trashed and it's difficult to recover from. It's trivial to do the same thing without using that option as well. – Jay Jun 09 '15 at 16:27
  • You know I've tried this but run GitBush "as Administrator" and it works. File `test1` - usual file w/o specific permissions. I confused what is a problem... – Kirby Jun 09 '15 at 18:40
  • > If the script fails your input file is trashed and it's difficult to recover from - Totally agree. :) – Kirby Jun 09 '15 at 18:43
  • 1
    I know the thread is old, but I just had the same problem under Windows. The fix was to just remove the Read-only flag of the directory containing the file(s)... – MartinW Jan 02 '20 at 13:31

1 Answers1

0

Most probably problem is with permissions of file test1, so solution will be simple to change it to be writable, or excluding -i option and redirecting to new file in writable folder
sed 's/a/b/g' test1 >somepath/newfile

josifoski
  • 1,696
  • 1
  • 14
  • 19