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.


Fwd: How to put numbers in front of selected lines?

2019-04-01 Thread Mark McLeod
I am incredibly rusty at shell scripts, but shouldn’t you be able to use the wc 
(word count) utility to find the number of lines? If so, 
the script could use ‘wc -l’ to check the number of lines, and spit its output 
to ‘wc -m’, which should count the number of characters in that output. Store 
that number to a $var, and call it using 'nl -w$var to ensure the correct 
number of digits even for files with large numbers of files.


> Begin forwarded message:
> 
> From: Rod Buchanan 
> Subject: Re: How to put numbers in front of selected lines?
> Date: April 1, 2019 at 10:26:52 AM EDT
> To: BBEdit-Talk List 
> Reply-To: bbedit@googlegroups.com
> 
> 
> One problem with -w2 is if the file is >= 100 lines it breaks:
> 
> $ nl -w2 -s'. ' ...
> 
> 98. 
> 99. 
> 00. 
> 01. 
> 02. 
> 
> $ nl -nrz -w2 -s'. ' ...
> 
> 98. 
> 99. 
> 00. 
> 01. 
> 02. 
> 
>> On Mar 30, 2019, at 3:04 AM, Christopher Stone > > wrote:
>> 
>> On 03/30/2019, at 02:35, Bill Kochman > > wrote:
>>> Chris, you wrote:
>>> 
>>> #!/usr/bin/env bash
>>> nl -nrz -w2 -s'. '
>>> 
>>> That works on all lines. What about if you have blank lines in the 
>>> document? While it works fine on files that have continuous lines of text, 
>>> the above indents two spaces and places a period on blank lines.
>> 
>> 
>> Hey Bill,
>> 
>> The -w2 switch (i.e. -w switch with 2 as its value), designates the width of 
>> the padded line number.
>> 
>> I think the addition of the period in blank lines is a bug in macOS' version 
>> of `nl`, because GNU `nl` doesn't have that problem.  (The indention will 
>> vary according to -w.)
>> 
>> 
>> #!/usr/bin/env bash
>> nl -nrz -ba -w3 -s'. '
>> 
>> This will number ALL lines including blank ones.
>> 
>> 
>> man nl in the Terminal will get you to the man page for `nl`, so you can see 
>> what the various switches do.
>> 
>> 
>> To work around your complaint you can install GNU `nl` with MacPorts or 
>> HomeBrew.
>> 
>> Or you can use a little `sed` to remove the floating period:
>> 
>> #!/usr/bin/env bash
>> nl -nrz -w2 -s'. ' | sed -E 's!^[[:blank:]]+\.!!'
>> 
>> 
>> --
>> Take Care,
>> 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 
>> .
> 
> -- 
> Rod Buchanan
> Kelly Supply Company
> 1004 W Oklahoma Ave
> Grand Island, NE 68802-1328
> 308 382-5670
> 308 382-8764 x1120
> 
> 
> -- 
> 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 
> .

-- 
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: How to put numbers in front of selected lines?

2019-04-01 Thread Rod Buchanan

One problem with -w2 is if the file is >= 100 lines it breaks:

$ nl -w2 -s'. ' ...

98. 
99. 
00. 
01. 
02. 

$ nl -nrz -w2 -s'. ' ...

98. 
99. 
00. 
01. 
02. 

> On Mar 30, 2019, at 3:04 AM, Christopher Stone  
> wrote:
> 
> On 03/30/2019, at 02:35, Bill Kochman  > wrote:
>> Chris, you wrote:
>> 
>> #!/usr/bin/env bash
>> nl -nrz -w2 -s'. '
>> 
>> That works on all lines. What about if you have blank lines in the document? 
>> While it works fine on files that have continuous lines of text, the above 
>> indents two spaces and places a period on blank lines.
> 
> 
> Hey Bill,
> 
> The -w2 switch (i.e. -w switch with 2 as its value), designates the width of 
> the padded line number.
> 
> I think the addition of the period in blank lines is a bug in macOS' version 
> of `nl`, because GNU `nl` doesn't have that problem.  (The indention will 
> vary according to -w.)
> 
> 
> #!/usr/bin/env bash
> nl -nrz -ba -w3 -s'. '
> 
> This will number ALL lines including blank ones.
> 
> 
> man nl in the Terminal will get you to the man page for `nl`, so you can see 
> what the various switches do.
> 
> 
> To work around your complaint you can install GNU `nl` with MacPorts or 
> HomeBrew.
> 
> Or you can use a little `sed` to remove the floating period:
> 
> #!/usr/bin/env bash
> nl -nrz -w2 -s'. ' | sed -E 's!^[[:blank:]]+\.!!'
> 
> 
> --
> Take Care,
> 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 
> .

-- 
Rod Buchanan
Kelly Supply Company
1004 W Oklahoma Ave
Grand Island, NE 68802-1328
308 382-5670
308 382-8764 x1120

-- 
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.