I need my script to edit and force write read
I have a script that alters lines in files. Which was working fine, but from hence forth, files will be read-only. I've tried changing wq to wq! (as I would in VI) but this has seemingly no effect. I've also tried "zz" which also did nothing.
I appreciate any help; thank you.
debug=false
## *****Put file name in quotes******
declare -a arr=("UF19905217" "UG19905218" )
##Put date in DDMMYYYY format for the date the message was original processed.
DATE="25082015"
## now loop through the above array
for i in "${arr[@]}"
do
#if "$debug; then
echo "Fix file named: Inbound_$i.msg"
MSG="Inbound_$i.msg"
#fi
if [ ! -d "$MSG" ]; then
# Enter what you would like changed here. You can copy and paste this command for multiple changes
#DATATYPE
printf "%sn" ',s/<DataType>EDI</DataType>/<DataType>830</DataType>/g' wq | ed -s /data1/Inbound/$DATE/$MSG
echo "Complete"
else
echo "Message not found or errored!"
fi
done
If you have write access on the directory containing the file, you can delete them before rewriting them. If you have access to GNU sed, that is what sed -i
will do.
I'm not familiar with ed
, but I think the following sed
command would do the equivalent of your command :
sed -i 's/<DataType>EDI</DataType>/<DataType>830</DataType>/g' /data1/Inbound/$DATE/$MSG
Also, if you are not the owner of the file, the directory must not have the sticky bit set or you won't be able to delete the file.
Add this to your .vimrc:
" Allow saving of files as sudo when I forgot to start vim using sudo.
cmap w!! w !sudo tee > /dev/null %
And then use ":w!!" and then ":q" instead of ":wq"
For a explanation of the command see this question
链接地址: http://www.djcxy.com/p/49584.html上一篇: 使用打开的文件更改Vim中的文件权限
下一篇: 我需要我的脚本来编辑并强制写入读取