sorting task

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

sorting task

meino.cramer

Hi,

is this possible with vim ?

I have (again ;) a config-file which consists of lines with elements
like this (example)

   a-6394-fgh-pnohkf-ajgd
   b-6394-fgh-pnohkf-ajgd
   a-ighj-daksjd-kk-k
   a-jhbvj-ogregi-knvc
   b-jhbvj-ogregi-knvc
   a-jhfks-iuer-dlfjk-vn
   b-jhfks-iuer-dlfjk-vn
   b-ttt-dkfj-iii-opk

Common to all elements is the start of the items with either 'a-' or
'b-'. Either there are pairsm wich differ only in "a-" or "b-" or
there is only one item of such a pair.

The original config-file consists of many of such lines.

Is it possible to sort the line in a way that allways corresponding
item are paired together like in the above example?

Sorry for my confusing "english"... ;)

Thanks a lot for any help in advance!
best regards,
mcc

--
Please don't send me any Word- or Powerpoint-Attachments
unless it's absolutely neccessary. - Send simply Text.
See http://www.gnu.org/philosophy/no-word-attachments.html
In a world without fences and walls nobody needs gates and windows.


--
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
Reply | Threaded
Open this post in threaded view
|

Re: sorting task

jreidthompson-2
Sorry if this double posts -- but it appears that my initial post
didn't make it

Use sort...
$ cat sortfile
a-6394-fgh-pnohkf-ajgd
b-6394-fgh-pnohkf-ajgd
a-ighj-daksjd-kk-k
b-jhfks-iuer-dlfjk-vn
a-jhfks-iuer-dlfjk-vn
b-ttt-dkfj-iii-opk
a-jhbvj-ogregi-knvc
b-jhbvj-ogregi-knvc
cyberhome: /home/rthompso>
$ sort  -t- +1 -2  sortfile
a-6394-fgh-pnohkf-ajgd
b-6394-fgh-pnohkf-ajgd
a-ighj-daksjd-kk-k
a-jhbvj-ogregi-knvc
b-jhbvj-ogregi-knvc
a-jhfks-iuer-dlfjk-vn
b-jhfks-iuer-dlfjk-vn
b-ttt-dkfj-iii-opk


--
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
Reply | Threaded
Open this post in threaded view
|

Re: sorting task

Tim Chase
In reply to this post by meino.cramer
> I have (again ;) a config-file which consists of lines with elements

> like this (example)
>
>    a-6394-fgh-pnohkf-ajgd
>    b-6394-fgh-pnohkf-ajgd
>    a-ighj-daksjd-kk-k
>    a-jhbvj-ogregi-knvc
>    b-jhbvj-ogregi-knvc
>    a-jhfks-iuer-dlfjk-vn
>    b-jhfks-iuer-dlfjk-vn
>    b-ttt-dkfj-iii-opk
>
> Common to all elements is the start of the items with either 'a-' or
> 'b-'. Either there are pairsm wich differ only in "a-" or "b-" or
> there is only one item of such a pair.
Does

   :sort /-/

do the job the way you want?

> Is it possible to sort the line in a way that allways corresponding
> item are paired together like in the above example?

The :sort command allows you to specify an offset pattern for
where it begins considering the search.  In the above, it's just
a dash, so it finds the first dash (after the "a-" or "b-") and
then sorts beginning at the next character.

For the broader multi-line case, it's often easiest to use the
"decorate, sort, undecorate" pattern, where you mash your grouped
lines together with a delimiter, sort the results, and then
un-mash the lines based on your delimiter.

> Sorry for my confusing "english"... ;)

If only my non-existent German (which I guess is your native
language given the .de TLD of your email address) was remotely as
good as your English. :)

-tim



--
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
Reply | Threaded
Open this post in threaded view
|

Re: sorting task

meino.cramer
In reply to this post by jreidthompson-2
jreidthompson <[hidden email]> [10-01-13 18:16]:

> Sorry if this double posts -- but it appears that my initial post
> didn't make it
>
> Use sort...
> $ cat sortfile
> a-6394-fgh-pnohkf-ajgd
> b-6394-fgh-pnohkf-ajgd
> a-ighj-daksjd-kk-k
> b-jhfks-iuer-dlfjk-vn
> a-jhfks-iuer-dlfjk-vn
> b-ttt-dkfj-iii-opk
> a-jhbvj-ogregi-knvc
> b-jhbvj-ogregi-knvc
> cyberhome: /home/rthompso>
> $ sort  -t- +1 -2  sortfile
> a-6394-fgh-pnohkf-ajgd
> b-6394-fgh-pnohkf-ajgd
> a-ighj-daksjd-kk-k
> a-jhbvj-ogregi-knvc
> b-jhbvj-ogregi-knvc
> a-jhfks-iuer-dlfjk-vn
> b-jhfks-iuer-dlfjk-vn
> b-ttt-dkfj-iii-opk
>
Hi,

thank you for your help! :)
Works like a charm !!!

Best regards,
mcc

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


--
Please don't send me any Word- or Powerpoint-Attachments
unless it's absolutely neccessary. - Send simply Text.
See http://www.gnu.org/philosophy/no-word-attachments.html
In a world without fences and walls nobody needs gates and windows.


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