Chinaunix首页 | 论坛 | 博客
  • 博客访问: 194317
  • 博文数量: 44
  • 博客积分: 2021
  • 博客等级: 大尉
  • 技术积分: 937
  • 用 户 组: 普通用户
  • 注册时间: 2007-06-03 22:55
文章分类

全部博文(44)

文章存档

2009年(2)

2008年(42)

我的朋友

分类: LINUX

2008-05-21 17:44:04

网上看的,比较有用
vim -e -s -c ":%s/old/new/g" -c ":wq" urfile
同理
vim -e -s -c ":1,$s/old/new/g" -c ":wq" urfile


       -e          Start Vim in Ex mode, just like the executable was called "ex".
       -s          Silent mode.  Only when started as "Ex" or when the "-e" option was given before the "-s" option.
       -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.

ex +:%s/old/new/g +:wq urfile
同理,这样也可以解决
在脚本里面非常有效
       Vim behaves differently, depending on the name of the command (the executable may still be the same file).

       vim       The "normal" way, everything is default.

       ex        Start  in  Ex  mode.  Go to Normal mode with the ":vi" command.  Can also be done with the "-e" argu-
                 ment.

       view      Start in read-only mode.  You will be protected from writing the files.  Can also be  done  with  the
                 "-R" argument.

:g/keyword/d                   ----把含有keyword的行删除

:g/^$/d
就是把空行删除
阅读(628) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~