sed-4.2.1 替换文件内容后变成只读文件

D:\zDown\00>cat test.txt
000
111
222
333

D:\zDown\00>attrib
A       I            D:\zDown\00\test.txt

D:\zDown\00>sed -i -e "s/$/&TTT/g" test.txt
sed: preserving permissions for `./sed003936': Permission denied

D:\zDown\00>attrib
A    R               D:\zDown\00\test.txt

D:\zDown\00>cat test.txt
000TTT
111TTT
222TTT

D:\zDown\00>sed --version
GNU sed version 4.2.1
Copyright (C) 2009 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE,
to the extent permitted by law.

GNU sed home page: <http://www.gnu.org/software/sed/>.
General help using GNU software: <http://www.gnu.org/gethelp/>.
E-mail bug reports to: <bug-gnu-utils@gnu.org>.
Be sure to include the word ``sed'' somewhere in the ``Subject:'' field.

D:\zDown\00>

 今天遇到的问题,百思不解为什么,后来换个sed-4.2.2 版本试了一下

D:\zDown\00>attrib -R +I

D:\zDown\00>attrib
A       I            D:\zDown\00\test.txt

D:\zDown\00>cat test.txt
000TTT
111TTT
222TTT

D:\zDown\00>sed-4.2.2 -i -e "s/$/&TTT/g" test.txt

D:\zDown\00>attrib
A       I            D:\zDown\00\test.txt

D:\zDown\00>cat test.txt
000TTTTTT
111TTTTTT
222TTTTTT

D:\zDown\00>sed-4.2.2 --version
sed-4.2.2 (GNU sed) 4.2.2
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Jay Fenlason, Tom Lord, Ken Pizzini,
and Paolo Bonzini.
GNU sed home page: <http://www.gnu.org/software/sed/>.
General help using GNU software: <http://www.gnu.org/gethelp/>.
E-mail bug reports to: <bug-sed@gnu.org>.
Be sure to include the word ``sed'' somewhere in the ``Subject:'' field.

D:\zDown\00>

sed-4.2.2 就正常,发现MSYS自带的sed版本确实有这个BUG

还有一种方法可以解决这个问题

sed -ie "s/00/11/g" 00.txt
sed: preserving permissions for `./sed051044': Permission denied

It's caused by Windows security settings.
Open the folder's Properties settings from the context menu. In the Security tab, click Edit, press Add... in the pop-up window and add your user to the list, check Full Control in the Allow column. Press OK twice to apply the changes.

posted @ 2020-09-10 23:10  1CM  阅读(566)  评论(0编辑  收藏  举报