Monday, August 31, 2009

Re: Use VIM to perform text manipulation on file (like sed/awk)

On Thu, Aug 27, 2009 at 2:55 PM, Christian Brabandt wrote:
...
> 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
> `----

Let me see if I got your script right. You tell sed to work on the
range from "-c" to first blank line right?
Then you instruct it to comment the lines that are not already in
comment in that range (which in this case is also a paragraph).
It should work well so long as $1 is the first line in the paragraph.

Thank you very much!
Yosi

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

No comments:

Post a Comment