Eric Leenman wrote:
Hi,
I have a long file which contains like:
##################################################
| 0 1 2 3 4 5 6
##################################################
Line 18 | 123
Line 19 | abc
--------------------------------------------------
Line 332 | xyz
##################################################
| 0 1 2 3 4 5 6
##################################################
Line 18 | 641
Line 19 | GHI
--------------------------------------------------
Line 332 | vcx
##################################################
| 0 1 2 3 4 5 6
##################################################
....
How do I sort this file so that
- all line 18 , i.e., comes under each other? And line 19 , and so on.
- removes the lines starting with ###
- removes the lines starting with ---
- removes the lines starting with spaces
So that what remains look like this:
...
Line 18 | 123
Line 18 | 641
Line 19 | abc
Line 19 | GHI
Line 332 | xyz
Line 332 | vcx
...
This request requires a multi-step process:
a) Delete the trash:
:v/\<Line\>/d
b) Next, you appear to want to sort the lines based on the text to the
left of the "|"s
(ie. Line 18, Line 332, etc). Because the remaining lines begin
with "Line", you
have several sorting options. You can just sort the lines using an
external sort:
:%!sort
If you're using vim 7.0, you can use the built-in sort:
:%sort
Some more types of sorting are supported by my vissort plugin
(http://mysite.verizon.net/astronaut/vim/index.html#VimFuncs
see "Visual Block Sorting") which allows one to sort lines based on
a visual-block,
or you can use my vis.vim plugin (..., see "Visual Block Commands") and
sort the visual block independently of surrounding text.
Regards,
Chip Campbell
P.S. Replying to an email but changing the subject line as you did here
can cause
folks to miss your post, if said folks are not interested in
the original subject
but happen to be interested in your subject. With mozilla,
for example, the
entire tree of articles and responses get grouped under the
original article.