Christian Brabandt wrote:
Hi Stahlman!

On Mi, 14 Apr 2010, Stahlman Family wrote:


...[snip]...

Or, to do it all in one fell swoop from the shell...

for i in 3 4 5 6; do sed -n $i~6p test.txt >test$((i-2)).out; done

You could do the same thing from within Vim by editing the file and doing...
:w !sed -n '3~6p' >test1.out
:w !sed -n '4~6p' >test2.out
.
.

In my opinion, these approaches are a bit simpler, but of course, they work only if you have POSIX tools on your system...

Actually, this only works with GNU sed. The "~"-adressing is a specialty that is not required by POSIX and I am not sure which other sed support it.

Good point. Those without GNU versions of sed could use something like...

for i in 1 2 3 4; do sed -n "$((i+2)){:L;p;n;n;n;n;n;n;b L}" \
test.txt test$i.out; done

...or using awk...

gawk '/^-[[:space:]]*$/{getline; for (i=1; i<=4; i++) { getline; \
print > "test" i ".out" }}' test.txt

Neither as simple as the GNU version, but still arguably simpler than the pure Vim approach...

Brett Stahlman



regards,
Christian


--
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

To unsubscribe, reply using "remove me" as the subject.

Reply via email to