Re: RegEx Challenge, Title Case a column in an CSV File

2019-04-11 Thread Christopher Stone
On 04/01/2019, at 10:59, Lee Hinde mailto:leehi...@gmail.com>> wrote:
> I have a CSV file where the 2nd column contains names that are being provided 
> all caps. I'd like to title case that column.
> 
> First column is a number, always, so:
> 
> 123,HUMAN RESOURCES,
> 124,PUBLICATIONS,
> 
> I'd like to convert that to:
> 
> 123,Human Resources,
> 124,Publications,
> 
> Is that doable with RegEx?  A quick google didn't provide anything I 
> understood. (low bar)


Hey Lee,

I've made a feature suggestion to add select contiguous columns to the BBEdit's 
edit columns suite.

If you're interested in same then it would help for you (and others) to make 
the same request.

Were this possible it'd be a simple 2-step process to complete the task with 
BBEdit.


I can't think of a way to do what you want with pure RegEx, but a little Perl 
in a Text Filter goes a long way:


#!/usr/bin/env perl -sw
use v5.12;
use utf8;

my ($col2);

while (<>) {
if ( m!^([^,]+,)([^,]+)(,.+)?! ) {
$col2 = $2;
$col2 = join '', map { ucfirst lc $_ } split /(\s+)/, $col2;
print "$1$col2$3\n";
}   else {
print;
}
}


--
Best Regards,
Chris

-- 
This is the BBEdit Talk public discussion group. If you have a 
feature request or need technical support, please email
"supp...@barebones.com" rather than posting to the group.
Follow @bbedit on Twitter: 
--- 
You received this message because you are subscribed to the Google Groups 
"BBEdit Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to bbedit+unsubscr...@googlegroups.com.
To post to this group, send email to bbedit@googlegroups.com.
Visit this group at https://groups.google.com/group/bbedit.


Re: RegEx Challenge, Title Case a column in an CSV File

2019-04-01 Thread Lee Hinde
I think this is the solution. Thanks.


> On Apr 1, 2019, at 12:05 PM, Roland Küffner  wrote:
> 
> As „title case“ is not a grep option (at least not to my knowledge) you have 
> two options: a) getting ambitious and thinking about scripting solution or b) 
> walk down the pragmatic way. That would be:
> Open the file in a spreadsheet app
> Copy the second column to BBEdit
> Text > Change Case > Title Case
> Paste it back into the spreadsheet
> Also: the younger incarnations of BBEdit give you some support for working 
> with columns. With the cursor in (any) column 2 of your text: Edit > Columns 
> > New Document with Columns. As above: change the case and copy the text back 
> using a vertical insertion selection and Columns > Rearrange
> 

-- 
This is the BBEdit Talk public discussion group. If you have a 
feature request or need technical support, please email
"supp...@barebones.com" rather than posting to the group.
Follow @bbedit on Twitter: 
--- 
You received this message because you are subscribed to the Google Groups 
"BBEdit Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to bbedit+unsubscr...@googlegroups.com.
To post to this group, send email to bbedit@googlegroups.com.
Visit this group at https://groups.google.com/group/bbedit.


Re: RegEx Challenge, Title Case a column in an CSV File

2019-04-01 Thread Roland Küffner
Am 1. Apr. 2019, 18:01 +0200 schrieb Lee Hinde :
> I have a CSV file where the 2nd column contains names that are being provided 
> all caps. I'd like to title case that column.
>
> First column is a number, always, so:
>
> 123,HUMAN RESOURCES,
> 124,PUBLICATIONS,
>
> I'd like to convert that to:
>
> 123,Human Resources,
> 124,Publications,
>
> Is that doable with RegEx?  A quick google didn't provide anything I 
> understood. (low bar)
The problem with this example data is, that you have a variable number of words 
that need to be „case-transformed“.  Regular expressions are a bit of a head 
scratcher when it comes to variable occurrences of targets. If you wanted to 
„sentence-case“ that column it would be rather easy:
search:
^(.+?),(.)(.+?),
replace:
\1,\u\2\L\3,
Check BBEdit Help > Grep > Writing Replacement Patterns for the \u\U\l\L\E 
specifiers.

But that would give you "123,Human resources,….“ instead of "123,Human 
Resources,….“ You could add more search-replace operations searching for a 
space and a lowercase character but that is kind of unsatisfying.
As „title case“ is not a grep option (at least not to my knowledge) you have 
two options: a) getting ambitious and thinking about scripting solution or b) 
walk down the pragmatic way. That would be:

1. Open the file in a spreadsheet app
2. Copy the second column to BBEdit
3. Text > Change Case > Title Case
4. Paste it back into the spreadsheet

Also: the younger incarnations of BBEdit give you some support for working with 
columns. With the cursor in (any) column 2 of your text: Edit > Columns > New 
Document with Columns. As above: change the case and copy the text back using a 
vertical insertion selection and Columns > Rearrange

Roland

-- 
This is the BBEdit Talk public discussion group. If you have a 
feature request or need technical support, please email
"supp...@barebones.com" rather than posting to the group.
Follow @bbedit on Twitter: 
--- 
You received this message because you are subscribed to the Google Groups 
"BBEdit Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to bbedit+unsubscr...@googlegroups.com.
To post to this group, send email to bbedit@googlegroups.com.
Visit this group at https://groups.google.com/group/bbedit.


RegEx Challenge, Title Case a column in an CSV File

2019-04-01 Thread Lee Hinde
I have a CSV file where the 2nd column contains names that are being 
provided all caps. I'd like to title case that column.

First column is a number, always, so:

123,HUMAN RESOURCES,
124,PUBLICATIONS,

I'd like to convert that to:

123,Human Resources,
124,Publications,

Is that doable with RegEx?  A quick google didn't provide anything I 
understood. (low bar)

-- 
This is the BBEdit Talk public discussion group. If you have a 
feature request or need technical support, please email
"supp...@barebones.com" rather than posting to the group.
Follow @bbedit on Twitter: 
--- 
You received this message because you are subscribed to the Google Groups 
"BBEdit Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to bbedit+unsubscr...@googlegroups.com.
To post to this group, send email to bbedit@googlegroups.com.
Visit this group at https://groups.google.com/group/bbedit.