Extracting lines from csv file which contain certain string on a specific column.

18 views
Skip to first unread message

mctamz

unread,
Sep 18, 2019, 7:45:29 AM9/18/19
to BBEdit Talk
Hi, a total newbie to this.

I was wondering if there is a way to extract certain lines which contain certain strings from a specific column in a csv file?
What I mean is, for instance, if there is a csv file of the following:

Canada,USA,France,Italy,Germany,Japan
Apple,Orange,Strawberry,Banana,Pear,Mango
One,Two,Three,Four,Five,Six
Banana,Orange,Apple,Strawberry,Mango,Pear
Blue,Yellow,Green,Red,Purple,Pink
Uno,Dos,Tres,Cuatro,Cinco,Seis
Red,Yellow,Pink,Purple,Green,Blue

I would want to extract the entire line which contains the string, "Strawberry" and "Green"  on the third column. 
The result would be:

Apple,Orange,Strawberry,Banana,Pear,Mango
Blue,Yellow,Green,Red,Purple,Pink


Is there a way of using regex?
Thanks.

Andrew Brown

unread,
Sep 18, 2019, 8:34:31 AM9/18/19
to bbe...@googlegroups.com
^([^,]+?),([^,]+?),(Strawberry|Green)(.+)\n replace with XyZ&

Text | Process Lines Containing… XyZ and Copy to clipboard

Simpler solutions abound no doubt.

AB

Jan Erik Moström

unread,
Sep 18, 2019, 8:34:31 AM9/18/19
to BBEdit Talk
On 18 Sep 2019, at 10:50, mctamz wrote:

> Apple,Orange,Strawberry,Banana,Pear,Mango
> Blue,Yellow,Green,Red,Purple,Pink
>
>
> Is there a way of using regex?

Quick and dirty solution, use the "process line containing" tool

Set ".*,.*,(Strawberry|Green),.*,.*,.*" as the regex and check "Copy to
new document".

Done (at least for this example)

= jem
Reply all
Reply to author
Forward
0 new messages