Removing unneeded data from rows

31 views
Skip to first unread message

anotherhoward

unread,
Jul 16, 2020, 8:01:18 AM7/16/20
to BBEdit Talk
In many (not all) of the row items in my text file, there are two carriage returns. One appears after 'NYM,,,,,' while the other appears at the item's end. In those items with two carriage returns, how can I remove everything after 'NYM,,,,,' which ends with a carriage return? 

Note: Rows 1-3 below have the problem. Rows 4-5 do not.

1,Tom Seaver\seaveto01,60,Ind. Games,42,10,.808,1.42,60,42,17,0,533.0,308,90,84,31,113,699,0.79,18,12,18.0,,,NYM,,,,,
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
2,Dwight Gooden\goodedw01,46,Ind. Games,32,6,.842,1.54,46,22,10,0,385.1,243,72,66,18,101,521,0.89,53,16,11.2,,,NYM,,,,,
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
3,Jacob deGrom\degroja01,41,Ind. Games,19,7,.731,1.77,41,0,0,0,284.1,184,64,56,16,66,447,0.88,25,9,7.8,1336.35,1905.33,NYM,,,,,
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
4,Dick Selma\selmadi01,2,Ind. Games,1,1,.500,2.12,2,1,1,0,17.0,10,4,4,1,3,23,0.76,1,2,0.6,,,NYM,,,,,
5,Ray Sadecki\sadecra01,2,Ind. Games,1,1,.500,2.20,2,1,0,0,16.1,14,4,4,0,4,22,1.10,0,0,0.3,,,NYM,,,,,


Bruce Van Allen

unread,
Jul 16, 2020, 10:36:35 AM7/16/20
to bbe...@googlegroups.com
On 7/16/20 at 5:01 AM, bbe...@googlegroups.com ('anotherhoward'
via BBEdit Talk) wrote:

>how can I remove everything after 'NYM,,,,,' which ends with a
>carriage return?
>Note: Rows 1-3 below have the problem. Rows 4-5 do not.
>
>1,Tom Seaver\seaveto01,60,Ind. Games,42,10,.808,1.42,60,42,17,0,533.0,308,90
>,84,31,113,699,0.79,18,12,18.0,,,NYM,,,,,
>,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,

Do the lines always have nothing but empty columns after the
'NYM' - i.e., nothing but commas? If so, you have some lines
that are only commas.

Find lines with nothing but commas:
^,+\n

Replace with nothing.

Interpretation:

^ start of line
,+ one or more commas
\n newline

If you wanted to also remove those extra commas after NYM:

Find
(NYM),+\n(,+\n)?

Replace with:
\1\n

(NYM) Find NYM and capture it via parens
,+ One or more commas
\n newline
(,+\n)? same pattern as first example, surrounded by parens and
followed by '?' to mean zero or one of that sub-pattern

Replacement:

\1 \1 stands for the first capture (NYM)
\n a newline right after NYM to replace the first newline

HTH
--

- Bruce

_bruce__van_allen__santa_cruz__ca_

anotherhoward

unread,
Jul 16, 2020, 12:24:45 PM7/16/20
to BBEdit Talk
Bruce,

Your response is great. If I want to extract all the text in each row up to and including the first carriage return, how can I do that?

Howard
Reply all
Reply to author
Forward
0 new messages