Friday, January 28, 2011

Re: Indpendant position marks for scripts ?

Ben Schmidt <mail_ben_schmidt@yahoo.com.au> [11-01-29 06:24]:
> On 29/01/11 3:42 PM, meino.cramer@gmx.de wrote:
> >
> >Hi,
> >
> >I want to process a text with script.
> >The text contains of two regions:
> >The first region contains of lines beginning with keyword_a
> >and the second one start with keyword_b.
> >I want to sort the first region using sort with pattern_a and
> >after that I want to sort the second region with pattern_b.
> >
> >I can set the start of the forst sort with
> >
> > : /keyword_a
> >
> >in the script. But I dont know how to limit the range of the first
> >sort so that only lines starting with keyword_a are sorted using
> >pattern_a. Same goes for the second region...
>
> Try something like
>
> :0/^a/,/^\(a\)\@!/sort
>
> It means loosely:
>
> : - perform an ex command
> 0 - from before the beginning of the file
> /^keyword_a/ - find a line beginning with 'keyword_a'
> , - and operate until
> / - we find
> ^ - the beginning of a line
> \(keyword_a\)\@! - where 'keyword_a' doesn't match
> /sort - with the sort command
>
> Ben.
>
>
>
> --
> You received this message from the "vim_use" maillist.
> Do not top-post! Type your reply below the text you are replying to.
> For more information, visit http://www.vim.org/maillist.php
>

Hi Ben,

...got some problems here...may be due to a not-so-exact description
of what I need...

I will try to explain... ;)

The file in its original version looks like this ( there is additional
text following keyword_[ab], which I left out here, but makes the
final
sort /<pattern>/
necessary).

something
different
fnord
foo
baz
gnu
keyword_a
noordszki
looping
tatdat
drool
socket
pipe
Unix
tools
cryptic
other-pipe
other-Unix
other-tools
other-cryptic
keyword_a
keyword_a
keyword_a
keyword_b
keyword_b
keyword_a
keyword_a
keyword_a
keyword_b
keyword_a
keyword_a
keyword_a
keyword_b
keyword_a
keyword_b
keyword_b

after the file is loaded, my script does a

:gg
:/keyword_a
:.,$sort

this way the file becomes

something
different
fnord
foo
baz
gnu
keyword_a
noordszki
looping
tatdat
drool
socket
pipe
Unix
tools
cryptic
keyword_a
keyword_a
keyword_a
keyword_a
keyword_a
keyword_a
keyword_a
keyword_a
keyword_a
keyword_a
keyword_b
keyword_b
keyword_b
keyword_b
keyword_b
keyword_b

:/^keyword_a/,/^\(keyword_a\)\@!/sort /<pattern>/

This line triggers an error saying: E493 Backward range given.

I looked into the help, which says that start and end of the range are
swapped and -- if the command is preceeded with :silent the start and
end will be automagically swapped.
I did this.

Now no error is given anymore but the the script does not work --
the sort of the above line ignores its /<pattern>/.

I have simply no glue :) what is happening here...

Thank you very much in advance for any enlightment! :)

Best regards,
mcc


--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments:

Post a Comment