Sorting by text position in BBEdit - making in the best spreadsheet editor ever

1,245 views
Skip to first unread message

Allen Hancock

unread,
Apr 23, 2012, 10:43:30 PM4/23/12
to bbe...@googlegroups.com
I get a lot of tabular text data I need to edit on a regular basis.

Excel mungs the data, where BBEdit just works.

However, I frequently need to sort the lines by the second/third/etc column, as defined by tabs in between the columns.

I'm not much on grep, so if someone would help out with the following two situations, I would be grateful:

Given 3 columns of text with tabs in between, what grep pattern (I assume that's the best way to handle this) would select the first character after the 2nd tab?

112 000 PDQ
987 000 DEF
090 000 XYZ
678 000 ABC

would become
678 000 ABC
987 000 DEF
112 000 PDQ
090 000 XYZ



given a column of part numbers which all begin  000-, how could I sort on the 5th character?

000-XYZ
000-PDQ
000-ABC
000-DEF

would become

000-ABC
000-DEF
000-PDQ
000-XYZ


Thank so much in advance!

-Allen

Rod Buchanan

unread,
Apr 24, 2012, 3:36:02 PM4/24/12
to bbe...@googlegroups.com
On Apr 23, 2012, at 9:43 PM, Allen Hancock wrote:

> Given 3 columns of text with tabs in between, what grep pattern (I assume that's the best way to handle this) would select the first character after the 2nd tab?
>
> 112 000 PDQ
> 987 000 DEF
> 090 000 XYZ
> 678 000 ABC
>
> would become
> 678 000 ABC
> 987 000 DEF
> 112 000 PDQ
> 090 000 XYZ

Use Text -> Sort Lines...

Check "Sort using pattern"
Searching pattern: ^(.+?)\t(.+?)\t(.+)
Sort using: Specific sub-patterns:
\3

--
Rod Buchanan
KDSI / Kelly Supply Co / ISCO
308 382-8764 x220

LuKreme

unread,
Apr 24, 2012, 6:17:52 PM4/24/12
to bbe...@googlegroups.com
On Apr 23, 2012, at 20:43, Allen Hancock <al...@macconsultinggroup.com> wrote:
> Given 3 columns of text with tabs in between, what grep pattern (I assume that's the best way to handle this) would select the first character after the 2nd tab?

[^\t]*\t[^\t]*\t([^\t]*)

Sort on \1

Basically what you are saying is, I want any number of characters (*) that are not a tab ([^\t]) followed by a tab, twice. Then, I want you to grab the next set of characters that are not tabs into a buffer () and since that's the first buffer, it will be named \1. Now sort on that buffer.


Allen Hancock

unread,
Feb 27, 2018, 9:36:25 AM2/27/18
to BBEdit Talk
Resurrecting this old thread of mine, what would the syntax be to sort by a specific column, regardless of content..

So, sort on column 8, etc.

Thanks all!

On Tuesday, April 24, 2012 at 10:17:52 PM UTC, Lewis Butler wrote:
Reply all
Reply to author
Forward
0 new messages