sort lines in reverse order

896 views
Skip to first unread message

Georg Portenkirchner

unread,
Nov 10, 2017, 8:58:43 AM11/10/17
to BBEdit Talk
I have a list that I want to sort in reverse order. So that 

Bob
Alex
Jack
Andy

becomes

Andy
Jack
Alex
Bob

How can I do this? Thanks in advance.

Donald Goyette

unread,
Nov 10, 2017, 9:35:44 AM11/10/17
to bbe...@googlegroups.com
You can do it with commands from the Text menu: first add line numbers, then sort lines with "numbers match by value" and "reverse sort" checked, then finally remove the line numbers.
--
This is the BBEdit Talk public discussion group. If you have a
feature request or would like to report a problem, please email
"sup...@barebones.com" rather than posting to the group.
Follow @bbedit on Twitter: <http://www.twitter.com/bbedit>
---
You received this message because you are subscribed to the Google Groups "BBEdit Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bbedit+un...@googlegroups.com.
To post to this group, send email to bbe...@googlegroups.com.

Rich Siegel

unread,
Nov 10, 2017, 9:51:26 AM11/10/17
to bbe...@googlegroups.com
On 11/10/17 at 3:30 AM, portenk...@gmail.com (Georg
Portenkirchner) wrote:

>I have a list that I want to sort in reverse order. So that
>Bob
>Alex
>Jack
>Andy
>
>becomes
>
>Andy
>Jack
>Alex
>Bob

The attached Perl one-liner will do it. Place it in your Text
Filters (Application Support/BBEdit/Text Filters/) and run it
from the "Apply Text Filter" command on the Text menu.

In case the attachment doesn't come through, the entire body of
the script is:

#!/usr/bin/env perl

print reverse <>;

Enjoy,

R.
--
Rich Siegel Bare Bones Software, Inc.
<sie...@barebones.com> <http://www.barebones.com/>

Someday I'll look back on all this and laugh... until they
sedate me.
Reverse.pl

Georg Portenkirchner

unread,
Nov 10, 2017, 12:58:19 PM11/10/17
to BBEdit Talk
Hi Donald,

I should have thought of that.

Thanks for the help and have a nice weekend

Georg

Georg Portenkirchner

unread,
Nov 10, 2017, 1:14:31 PM11/10/17
to BBEdit Talk
Thanks Rich, this solution is even better than Donald's idea.

Have a nice weekend!

And thanks a lot for a great product. I am using BBEdit since 1994 for all my texts, lists, ideas etc.
It is the first program I install when getting a new Mac.

Christopher Stone

unread,
Nov 10, 2017, 9:56:14 PM11/10/17
to BBEdit-Talk
On 11/10/2017, at 02:30, Georg Portenkirchner <portenk...@gmail.com> wrote:
I have a list that I want to sort in reverse order.


Hey Georg,

Rich has provided an elegant Perl filter.

#!/usr/bin/env perl
print reverse <>;

Just for fun here's how you can do it with AppleScript:

------------------------------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2017/11/10 20:30
# dMod: 2017/11/10 20:39 
# Appl: BBEdit
# Task: Reverse Lines of Selection - or whole document if there is NO selection.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @BBEdit, @Reverse, @Lines, @Selection, @Document
------------------------------------------------------------------------------

tell application "BBEdit"

    

    set theTarget to selection

    

    if length of theTarget = 0 then set theTarget to front text window

    

    set theLines to contents of lines of text of theTarget

    

    if theLines ≠ {} then
        set AppleScript's text item delimiters to linefeed
        set theLines to ((reverse of theLines) & "") as text
    end if

    

    set contents of theTarget to theLines

    

end tell

------------------------------------------------------------------------------

--
Best Regards,
Chris

Reply all
Reply to author
Forward
0 new messages