[comp.editors] vi - alphabetical sort

neman@sunee.waterloo.edu (Neman "Napalm" Syed) (12/13/90)

Hi!  Another question from another vi-illiterate.  How does one
perform an alphabetical sort of all items in a file?  The
specific file I'm thinking of is my very non-alphabetical
.newsrc, which I'd love to have organized.  Is this possible?

-- 
Neman Syed - Rebel Without A Clue
neman@sunee.uwaterloo.ca    or    neman@108.watstar.uwaterloo.ca
Opinions expressed are solely those of my employers and in
no way affect or represent those of Neman Syed.

sanjiv@hoss.unl.edu (Sanjiv K. Bhatia) (12/13/90)

In article <1990Dec12.214128.16549@sunee.waterloo.edu> neman@sunee.waterloo.edu (Neman "Napalm" Syed) writes:
>Hi!  Another question from another vi-illiterate.  How does one
>perform an alphabetical sort of all items in a file?  The
>specific file I'm thinking of is my very non-alphabetical
>.newsrc, which I'd love to have organized.  Is this possible?

From within vi, issue this command:

	:%!sort

>-- 
>Neman Syed - Rebel Without A Clue
>neman@sunee.uwaterloo.ca    or    neman@108.watstar.uwaterloo.ca
>Opinions expressed are solely those of my employers and in
>no way affect or represent those of Neman Syed.


--
Sanjiv K. Bhatia				Department of Computer Science
sanjiv@fergvax.unl.edu				Ferguson Hall 115
voice: (402)-472-3485				University of Nebraska - Lincoln
fax:   (402)-472-7767				Lincoln, NE 68588-0115

tchrist@convex.COM (Tom Christiansen) (12/13/90)

In article <1990Dec12.214128.16549@sunee.waterloo.edu> neman@sunee.waterloo.edu (Neman "Napalm" Syed) writes:
>Hi!  Another question from another vi-illiterate.  How does one
>perform an alphabetical sort of all items in a file?  

    :%!sort

will do it.    Why you would want to go into the editor just to do 
this, I do not know.

--tom
--
Tom Christiansen		tchrist@convex.com	convex!tchrist
"With a kernel dive, all things are possible, but it sure makes it hard
 to look at yourself in the mirror the next morning."  -me

Phillip.Everson@uk.sun.com (Phillip Everson - Sun UK - CS Hotline) (12/13/90)

In article <1990Dec12.214128.16549@sunee.waterloo.edu>,
neman@sunee.waterloo.edu (Neman "Napalm" Syed) writes:
|> Hi!  Another question from another vi-illiterate.  How does one
|> perform an alphabetical sort of all items in a file?  The
|> specific file I'm thinking of is my very non-alphabetical
|> .newsrc, which I'd love to have organized.  Is this possible?
|> 
|> -- 
|> Neman Syed - Rebel Without A Clue
|> neman@sunee.uwaterloo.ca    or    neman@108.watstar.uwaterloo.ca
|> Opinions expressed are solely those of my employers and in
|> no way affect or represent those of Neman Syed.

Try

1G!Gsort <RETURN>

Phillip Everson
Sun UK

gbastin@x102c.harris-atd.com (Gary Bastin 60293) (12/14/90)

In article <1990Dec12.214128.16549@sunee.waterloo.edu
neman@sunee.waterloo.edu (Neman "Napalm" Syed) writes:
>Hi!  Another question from another vi-illiterate.  How does one
>perform an alphabetical sort of all items in a file?  The
>specific file I'm thinking of is my very non-alphabetical
>.newsrc, which I'd love to have organized.  Is this possible?

vi .newsrc
:1,$!sort

or

:%!sort

will do it.

If there are a few things that you would like to leave first, put those
items at the top of your .newsrc file, move the cursor to the first line
after the reserved "first" items, and do

<esc> .,$!sort

This sorts all the lines from the current cursor position to the
end of the file.  This way, the newly added newsgroups get put in
alphabetical order AFTER your favorite newsgroups.

Gary Bastin, WB4YAF      /-/-/      Internet: gbastin@x102c.ess.harris.com
Mail Stop 102-4826         |        phone: (407) 729-3045
Harris Corporation GASD    |        
P.O.B. 94000, Melbourne FL 32902    Speaking from, but not for, Harris! 

dattier@ddsw1.MCS.COM (David W. Tamkin) (12/15/90)

tchrist@convex.COM (Tom Christiansen) wrote in <110900@convex.convex.com>:

| In article <1990Dec12.214128.16549@sunee.waterloo.edu>
| neman@sunee.waterloo.edu (Neman "Napalm" Syed) writes:
| >Hi!  Another question from another vi-illiterate.  How does one
| >perform an alphabetical sort of all items in a file?  
| 
|     :%!sort
| 
| will do it.

Better by far to use sort -d.  Without -d, period precedes colon, so if you
subscribe to any group whose left-anchored name is included in the name of
another group, your .newsrc will end up in a strange order: rec.humor.d and
rec.humor.funny before rec.humor, alt.bbs.ads and alt.bbs.internet before
alt.bbs, etc.

| Why you would want to go into the editor just to do this, I do not know.

I don't either, unless you're already editing your .newsrc to subscribe or
unsubscribe various groups or to delete the article number listings for
unsubscribed groups.

I occasionally run my own .newsrc through %!sort -d, :g/!..*/s//!/ (to get
rid of the wasted information that gets stuck there whenever an article is
crossposted to both a group I read and a group I don't), and :g/!/m$ (to put
unsubscribed groups at the end; :g/:/m0 would put subscribed groups at the
beginning but it reverses their current order).

David Tamkin  Box 7002  Des Plaines IL  60018-7002  708 518 6769  312 693 0591
MCI Mail: 426-1818  GEnie: D.W.TAMKIN  CIS: 73720,1570   dattier@ddsw1.mcs.com