Removing part of a string

52 views
Skip to first unread message

Howard

unread,
Nov 13, 2020, 8:27:05 AM11/13/20
to BBEdit Talk
I have a dataset with a number of lines of data like this one:

1956,ML,Don Newcombe\newcodo01,BRO,4.5,27,7,0,3.06,268.0,139

In each line, in its third entry (in the above it is Don Newcombe\newcodo01) I want to remove everything from the backslash up to but not including its ending comma, so for the above line the output would be this: 

1956,ML,Don Newcombe,BRO,4.5,27,7,0,3.06,268.0,139

How can I do that?

Thanks,
Howard

Jan Erik Moström

unread,
Nov 13, 2020, 8:40:24 AM11/13/20
to BBEdit Talk
On 13 Nov 2020, at 14:27, Howard wrote:

> **1956,ML,Don Newcombe\newcodo01,BRO,4.5,27,7,0,3.06,268.0,139**

If there are no other places the backslash can appear the simplest would be

Search: \\.*?,
Replace: ,

or if it's always "\newcodo01"

Search: "\newcodo01" (grep search off)
Replace:

Robin Beech

unread,
Nov 13, 2020, 9:33:34 AM11/13/20
to BBEdit Talk
grep search for 

\\[^,]+

and replace with nothing

Tim A

unread,
Nov 13, 2020, 11:14:54 AM11/13/20
to BBEdit Talk
Curio. Both suggested Search patterns will also "see" themselves and match in the three lines of text below. Why?

1956,ML,Don Newcombe\newcodo01,BRO,4.5,27,7,0,3.06,268.0,139
\\.*?,
\\[^,]+


Jan Erik Moström

unread,
Nov 13, 2020, 12:37:51 PM11/13/20
to BBEdit Talk
On 13 Nov 2020, at 17:07, Tim A wrote:

> Curio. Both suggested Search patterns will also "see" themselves and
> match in the three lines of text below. Why?
>
>
>
> 1956,ML,Don Newcombe\newcodo01,BRO,4.5,27,7,0,3.06,268.0,139
>
> \\.*?,
>
> \\[^,]+

These patterns says

1. Match any characters from a backslash until (and including) the first
comma. All three lines match this
2. Match any characters that are not a common from a backslash. All
lines match this also.

= jem

Tim A

unread,
Nov 13, 2020, 1:53:33 PM11/13/20
to BBEdit Talk
Ah! Hiding in plain sight :>)
Thanks.

Howard

unread,
Nov 15, 2020, 4:53:47 PM11/15/20
to BBEdit Talk
Thanks jem, your first solution is what I needed.
Reply all
Reply to author
Forward
0 new messages