grep about non-greedy limit

24 views
Skip to first unread message

Ptarmigan

unread,
Aug 20, 2008, 3:23:23 AM8/20/08
to BBEdit Talk
I'm processing some v simple .txt data into a form it can be nicely
introduced into Filemaker

The data is like this:

south
R
P
B

north
R
R
R
N

In reality, the lists are much, much longer.

I want to be able to grab all the south or north entries separately,
and do stuff to them.

Capturing lines starting w an uppercase letter is easy, clearly. But
how do you do a pattern wh stops grabbing lines when it encounters a
line beginning \r ?

I don't mind if this is a no-brainer, I'd just like to know.

ptarmigan

Jon

unread,
Aug 20, 2008, 7:52:52 AM8/20/08
to BBEdit Talk
That is matching a bloc:

(south\r(([A-Z]\r)+)\r)

or

(north\r(([A-Z]\r)+)\r)

You can combine then in by :

Replace ((Partten1)*)((Partteen2)*) By \3\1 # (adjust number)


For example process many time

AAAABBBBAAAABBBBBAAABBB

With
replace ((B)*)((A)*) by \3\1


Another way is to transform a bloc into a single line, and to sort
lines (fix steps)

Replace \r([A-Z])$ by _\1

Sort lines,

Replace _([A-Z]) by \r\1

Ptarmigan

unread,
Aug 20, 2008, 12:59:35 PM8/20/08
to BBEdit Talk
Thanks a lot

I followed yr idea of putting the data on one tab-separated line: that
makes things much easier

I got it done.
Reply all
Reply to author
Forward
0 new messages