项目需要一个Windows主机从服务器上下载一个rdp文件对其他Windows主机进行远程管理,这个rdp文件由很多配置指令组成,本来打算在Linux服务器上对某些配置进行修改,再将rdp文件传给用户,然而使用sed指令后再传给Windows产生乱码,不能识别为rdp文件,猜测可能和Linux Windows对文件不同编码方式有关。查了半天也不知道怎么解决。无奈只好用vim,要求只用命令行,即不进入vim完成文件操作。
在vim的man文档中看到这么一句:
+{command}
-c {command}
{command} will be executed after the first file has been read. {command} is interpreted as an Ex command. If the {command} contains
spaces it must be enclosed in double quotes (this depends on the shell that is used). Example: Vim “+set si” main.c
Note: You can use up to 10 “+” or “-c” commands.
也就是说,在vim filename
后面用-c
或者+
可以不进入vim进行操作,注意指令如果有空格要用引号包起来。
于是这样写就OK啦
vim Default.rdp +":s/^full.*$/full address:s:192.168.0.1" +wq
就是说在rdp文件里找到full开头的一行改为full address:s:192.168.0.1,保存退出。