Hi WL!

On Mo, 24 Aug 2009, WL wrote:

> #Company IT nameservers
> nameserver 1.2.3.4
> nameserver 1.2.3.5
> nameserver 1.2.3.6
> 
> #Lab1 nameservers
> #nameserver 10.1.2.3
> #nameserver 10.1.2.4
> 
> #Lab2 nameservers
> #nameserver 20.1.2.2
> 
> I want to use vim -c to do to tasks.
> a- comment out a given section (say section that starts with comment
> #Company IT )
> b- uncomment a given section (say section that starts with comment
> #Lab1)

I haven't tested it thoroughly, but this sed script seems to work for 
me:
,----
| #!/bin/sh
| 
| 
| if [ "$1" = "-c" ]; then
|     COMMENT='yes';
|     shift;
| else
|     COMMENT='no';
| fi
| 
| if [ "$COMMENT" = "yes" ]; then
|     sed -i "/$1/,/^$/s/^[^#]/#&/g" "$2"
| else
|     sed -i "/$1/,/^$/s/^#\+//g" "$2"
| fi
`----


regards,
Christian
-- 
:wq!

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply via email to