how to use the line sort?

226 views
Skip to first unread message

Rendereason

unread,
Oct 11, 2011, 6:26:02 PM10/11/11
to TextWrangler Talk
I have a text that lists some numbers in lines, which I want sorted.
for example:
GBPC_DICDI vs. Q8I719_PLAF7: 9.09% identity
GLSA2_BRAJA vs. Q8I719_PLAF7: 23.26% identity

I would want to find the numbers preceding "% identity" and sort the
lines based on that, in order to see the text in order of high-to-low
identity values or vice versa.

Christopher Bort

unread,
Oct 11, 2011, 9:09:31 PM10/11/11
to textwr...@googlegroups.com

You'll need to use 'Sort using pattern' since you're sorting on
text that's in the middle of the lines. Just to be clear
'pattern' means a grep pattern (regular expression). Capture the
text that matches your percentage to a subpattern using
parentheses in the pattern, then sort using that subpattern.
Since you're sorting numbers, you'll also need to check the
'Numbers match by value' option to sort the lines numerically.

For the example you gave, and assuming that the percentages may
or may not have a decimal part, this pattern works:

(\d+\.?\d*)\%

and sort using either all patterns (there's only one subpatter
defined) or the specific subpattern \1.
--
Christopher Bort
<top...@thehundredacre.net>

Reply all
Reply to author
Forward
0 new messages