Sort on column postion

682 views
Skip to first unread message

Frere Roy

unread,
Sep 26, 2016, 12:05:56 PM9/26/16
to BBEdit Talk
I have some data that I would like to sort (reorder) on the 44th and 45th column which is the "month" field. 0912,05

Is this possible in BBedit


Maxxxxie Fxxxxg                          29/09/1984                
Mxxxxxs xxxxter                           29/12/1940               
Mxxxe Gxxxxxv                            29/05/1961                

Thanks for any help

Patrick Woolsey

unread,
Sep 26, 2016, 1:08:01 PM9/26/16
to bbe...@googlegroups.com
You can indeed do this by using BBEdit's "Sort Lines" command
together with a suitable grep pattern to isolate whatever
content you want to base the sort on.

For example, based on your current description and sample data,
please try this:

Choose Text -> Sort Lines to bring up the Sort Lines sheet, then
turn ON the options "Numbers match by value", "Sorted lines
replace selection", and "Sort using pattern" and enter a
"Searching pattern:" of

^.+?/(\d{2}).+?$

and "Specific sub-patterns:" of \1

This searching pattern will start matching at the beginning of
every line ^ and non-greedily match one or more characters .+?
up to a forward slash /, then capture the following two digits
\d{2} in this pattern's first (and only) sub-pattern by
enclosing them in parenthesis, and finally match a run of
characters .+? up to the end of the line $.

Then, when you run the Sort Lines command, BBEdit will capture
the contents of the first sub-pattern (specified by \1) from
each line, and sort the document based on those two-digit pairs.

(PS: This option is easier to use than to describe :-) so please
give it a try and let me know if you have any questions.)


Regards,

Patrick Woolsey
==
Bare Bones Software, Inc. <http://www.barebones.com/>

Frere Roy

unread,
Sep 26, 2016, 4:21:24 PM9/26/16
to BBEdit Talk
Grateful thanks - works as expected - also very useful in furthering understanding of GREP.

Frere Roy

unread,
Sep 27, 2016, 8:36:27 AM9/27/16
to BBEdit Talk
If my date was in US format with the month at the beginning, how could I sort on the 2 numbers BEFORE the slash?

Maxxxxie Fxxxxg                          09/29/1984                
Mxxxxxs xxxxter                           12/29/1940               
Mxxxe Gxxxxxv                            05/29/1961                

Thanks.


Le lundi 26 septembre 2016 18:05:56 UTC+2, Frere Roy a écrit :

Rod Buchanan

unread,
Sep 27, 2016, 9:18:05 AM9/27/16
to bbe...@googlegroups.com
Change the searching pattern to this:

^.+?(\d{2})/.+?$


--
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.
Visit this group at https://groups.google.com/group/bbedit.

-- 
Rod


Frere Roy

unread,
Sep 27, 2016, 12:57:48 PM9/27/16
to BBEdit Talk
Works brilliantly. Many thanks.This is in fact sufficient for my present needs but for elegance in the output file, would it be at all possible to sort first on the second figures (month in EU format) then by day (first figures EU format)?

Thanks.

Le lundi 26 septembre 2016 18:05:56 UTC+2, Frere Roy a écrit :
I have some data that I would like to sort (reorder) on the 44th and 45th column which is the "month" field. 0912,05

Is this possible in BBedit


Maxxxxie Fxxxxg                          19/09/1984                
Mxxxxxs xxxxter                           06/12/1940               
Mxxxe Gxxxxxv                            03/05/1961                
Mxxxe Gxxxxxv                            23/05/1961                

Thanks for any help

Rod Buchanan

unread,
Sep 27, 2016, 1:15:05 PM9/27/16
to bbe...@googlegroups.com
Like this:

Searching pattern:
^.+?(\d{2})/(\d{2})/.+?$
Specific sub-patterns:
\2 \1

To sort year/month/day

Searching pattern:
^.+?(\d{2})/(\d{2})/(\d{4}).+?$
Specific sub-patterns:
\3 \2 \1


--
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.
Visit this group at https://groups.google.com/group/bbedit.

-- 
Rod


Frere Roy

unread,
Sep 27, 2016, 1:59:18 PM9/27/16
to BBEdit Talk
Amazing. Many thanks. Hope that this may help some others.


Le lundi 26 septembre 2016 18:05:56 UTC+2, Frere Roy a écrit :
Reply all
Reply to author
Forward
0 new messages