Re: Need help simplifying apple script with grep

2023-03-18 Thread Kaveh Bazargan
All sounds good Mathias. I miss AppleScript. I wrote a lot of it to help
editing videos. It's just that grep is hard to read as it is!!

Perhaps not relevant, but I recently found Text Factory in BBEdit that lets
you string lots of greps together...

Regards
Kaveh

On Sat, 18 Mar 2023 at 11:45, Mathias  wrote:

> Huge thanks Bruce. You guys are insane at grep'ing, sed'ing etc. The
> answers I've gotten in here are like machine code sometimes. :)
>
> Kaveh, the reason I use AppleScript is because I've used it outside BBEdit
> in the past, so I'm most familiar with that setup. I've gotten solid
> evidence in here previously that it's probably not the best tool for the
> job, but when you deal with this stuff once every three years you kind of
> don't have time to learn something new... (I probably should I guess).
> Again, thanks.
>
> fredag 17 mars 2023 kl. 16:18:21 UTC+1 skrev Kaveh Bazargan:
>
>> Thanks Bruce. I am familiar with grep and use it a lot. Also used a lot
>> of AppleScript in the past but no regex in that.
>>
>> It's just that the extra escape and all the verbosity in AppleScript
>> makes it painful to decode!
>>
>> On Fri, 17 Mar 2023 at 14:30, Bruce Van Allen  wrote:
>>
>>> Yes, double escapes are needed. As handy as Applescript is, quoting is a
>>> major pain point.
>>>
>>> ‘*’ has special meaning within regular expressions, so it must be
>>> escaped when trying to match a literal ‘*’. So that's the first ‘\’. Then
>>> Applescript needs that ‘\’ escaped, so we get ‘\\*’.
>>>
>>> The BBEdit User Manual (PDF download via the Help menu) has a good
>>> discussion of this.
>>>
>>> — Bruce
>>>
>>> _bruce__van_allen__santa_cruz_ca_
>>>
>>>
>>>
>>>
>>>
>>> > On Mar 17, 2023, at 7:23 AM, Kaveh Bazargan 
>>> wrote:
>>> >
>>> > Quick question: For AppleScript you need to double escape, right? so:
>>> > •
>>> > in AppleScript: \\*
>>> > • becomes \* in BBEdit
>>> > • to find "*"
>>> >
>>> >
>>> > On Fri, 17 Mar 2023 at 13:36, Bruce Van Allen  wrote:
>>> > Oops - I mis-typed one bit: the inner part of the find pattern should
>>> be “[^*]” - asterisk instead of plus sign.
>>> >
>>> > tell application “BBEdit"
>>> >   tell front text window
>>> > replace "/\\*([^*]*?)\\*/" using "" options ¬
>>> > {search mode:grep, case sensitive:false, starting at top:true}
>>> >   end tell
>>> > end tell
>>> >
>>> >
>>> > — Bruce
>>> >
>>> > _bruce__van_allen__santa_cruz_ca_
>>> >
>>> >
>>> >
>>> >
>>> >
>>> > > On Mar 17, 2023, at 6:08 AM, Bruce Van Allen 
>>> wrote:
>>> > >
>>> > > Here’s a slightly amended version of your script:
>>> > >
>>> > > tell application “BBEdit”
>>> > >  tell front text window
>>> > >replace "/\\*([^+]*?)\\*/" using "" options ¬
>>> > > {search mode:grep, case sensitive:false, starting at top:true}
>>> > >  end tell
>>> > > end tell
>>> > >
>>> > > The differences are:
>>> > >
>>> > > - no parentheses () surrounding the whole find pattern because that
>>> becomes the first capture, which you use in the replacement pattern as ‘\1’.
>>> > >
>>> > > - added parens around the inner part of the find pattern, in order
>>> to capture what’s between the JS comment markers.
>>> > >
>>> > > -  if you needed to keep that outer parens capture for some other
>>> reason, then change the replacement pattern to “” (assuming that
>>> part stays the second parens-capture).
>>> > >
>>> > > - I omitted the replace “%@“ line to keep this part of the script
>>> clear.
>>> > >
>>> > > Using the script as I wrote it above
>>> > >
>>> > > /* some commented stuff */ /*some more*/
>>> > >
>>> > > And /* some more*/
>>> > >
>>> > > is transformed in one step into
>>> > >
>>> > >  
>>> > >
>>> > > And 
>>> > >
>>> > >
>>> > > HTH
>>> > >
>>> > >— Bruce
>>> > >
>>> > > _bruce__van_allen__santa_cruz_ca_
>>> > >
>>> > >
>>> > >
>>> > >
>>> > >
>>> > >> On Mar 17, 2023, at 3:04 AM, Mathias  wrote:
>>> > >>
>>> > >> OK, so I'm working on an apple script to replace Localizable
>>> (apple) comments on the /* ... */ format to 
>>> > >>
>>> > >> I got it working, but I'm using two commands because I couldn't
>>> figure the grep out... can this be simplified with only one "replace" ?
>>> > >>
>>> > >> pointers appreciated, script here:
>>> > >>
>>> > >> tell application "BBEdit"
>>> > >> tell front text window
>>> > >> replace "(/\\*[^\\*]*\\*/)" using "" options ¬
>>> > >> {search mode:grep, case sensitive:false, starting at top:true}
>>> > >> replace "(/\\*|\\*/)" using "" options {search mode:grep, case
>>> sensitive:false, starting at top:true}
>>> > >> replace "%@" using "%1$s" options {case sensitive:false, starting
>>> at top:true}
>>> > >>
>>> > >> end tell
>>> > >> end tell
>>> > >>
>>> > >> --
>>> > >> This is the BBEdit Talk public discussion group. If you have a
>>> feature request or need technical support, please email "
>>> sup...@barebones.com" rather than posting here. Follow @bbedit on
>>> Twitter: 
>>> > >> ---
>>> > >> You received this message 

Re: Need help simplifying apple script with grep

2023-03-18 Thread Bruce Van Allen
> On Mar 17, 2023, at 09:29, you wrote:
>> Yes, double escapes are needed. As handy as Applescript is, quoting is a 
>> major pain point.
> 
> 
> Not if you use Script Debugger.


Thanks for the reminder! I use Script Debugger, but hadn’t been using that 
capability.

— Bruce

_bruce__van_allen__santa_cruz_ca_


-- 
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 here. 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 view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/D6F910FC-CD24-43DD-8924-FEA3F092FD1F%40cruzio.com.


Re: Need help simplifying apple script with grep

2023-03-18 Thread Christopher Stone
On Mar 17, 2023, at 09:29, Bruce Van Allen  wrote:
> Yes, double escapes are needed. As handy as Applescript is, quoting is a 
> major pain point.


Not if you use Script Debugger .

SD has a “Paste as String Literal” command that automates the double-quoting as 
necessary.

I don't know for certain if the freeware "lite" version has this command, but I 
think it likely – since it's not listed in the feature comparison chart:

https://latenightsw.com/sd8/feature-comparison/

To go the other direction you can display the string in a result-viewer and 
select “Best View” and copy – or you can just set the clipboard to the string.

With just a little set-up this issue is trivial to manage.

-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 here. 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 view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/08426B1C-3690-4A1D-A8E8-2B00412BFC68%40gmail.com.


Re: Displaying TSV files

2023-03-18 Thread Neil Faiman
If your goal is, very specifically, to be sure that every line in your file has 
17 tabs in it, there is a simple solution.

>From the BBEdit Text menu, choose “Process lines containing…”.

Choose the “Find lines that … do not contain: option.
In the search field, enter

([^\t]*\t){17}

Check the Grep option, choose your preferred result options, and click Process. 
You will get a list (or report, or whatever) of all the lines in your file that 
don’t contain 17 tabs.

Cheers,
Neil Faiman

> On Mar 17, 2023, at 6:35 PM, Laurel Cooper  wrote:
> 
> I work with large, tsv-formatted text files The files are 17 column text 
> files with the columns separated by tabs.  I need to be able to see that none 
> of the tabs are missing. 
> I can see the tab stops by turning on "Show invisibles", but in some lines 
> the tabs are basically on top of each other, and in other places, the text is 
> on top of them.  
> Is there a better way to display these files? 
> I took a screen shot as an example:
> Thanks!
> 
> 
> 
> -- 
> 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 here. 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 view this discussion on the web visit 
> https://groups.google.com/d/msgid/bbedit/a0702843-bbee-486f-a828-0bb6faff8d51n%40googlegroups.com
>  
> .
> 

-- 
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 here. 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 view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/736F901C-C72D-4C92-9A3F-C235ED7F2FB5%40faiman.org.


Re: Need help simplifying apple script with grep

2023-03-18 Thread Mathias
Huge thanks Bruce. You guys are insane at grep'ing, sed'ing etc. The 
answers I've gotten in here are like machine code sometimes. :)

Kaveh, the reason I use AppleScript is because I've used it outside BBEdit 
in the past, so I'm most familiar with that setup. I've gotten solid 
evidence in here previously that it's probably not the best tool for the 
job, but when you deal with this stuff once every three years you kind of 
don't have time to learn something new... (I probably should I guess). 
Again, thanks.

fredag 17 mars 2023 kl. 16:18:21 UTC+1 skrev Kaveh Bazargan:

> Thanks Bruce. I am familiar with grep and use it a lot. Also used a lot 
> of AppleScript in the past but no regex in that. 
>
> It's just that the extra escape and all the verbosity in AppleScript makes 
> it painful to decode!
>
> On Fri, 17 Mar 2023 at 14:30, Bruce Van Allen  wrote:
>
>> Yes, double escapes are needed. As handy as Applescript is, quoting is a 
>> major pain point.
>>
>> ‘*’ has special meaning within regular expressions, so it must be escaped 
>> when trying to match a literal ‘*’. So that's the first ‘\’. Then 
>> Applescript needs that ‘\’ escaped, so we get ‘\\*’.
>>
>> The BBEdit User Manual (PDF download via the Help menu) has a good 
>> discussion of this.
>>
>> — Bruce
>>
>> _bruce__van_allen__santa_cruz_ca_
>>
>>
>>
>>
>>
>> > On Mar 17, 2023, at 7:23 AM, Kaveh Bazargan  
>> wrote:
>> > 
>> > Quick question: For AppleScript you need to double escape, right? so:
>> > • 
>> > in AppleScript: \\*
>> > • becomes \* in BBEdit
>> > • to find "*"
>> > 
>> > 
>> > On Fri, 17 Mar 2023 at 13:36, Bruce Van Allen  wrote:
>> > Oops - I mis-typed one bit: the inner part of the find pattern should 
>> be “[^*]” - asterisk instead of plus sign.
>> > 
>> > tell application “BBEdit"
>> >   tell front text window
>> > replace "/\\*([^*]*?)\\*/" using "" options ¬
>> > {search mode:grep, case sensitive:false, starting at top:true}
>> >   end tell
>> > end tell
>> > 
>> > 
>> > — Bruce
>> > 
>> > _bruce__van_allen__santa_cruz_ca_
>> > 
>> > 
>> > 
>> > 
>> > 
>> > > On Mar 17, 2023, at 6:08 AM, Bruce Van Allen  wrote:
>> > > 
>> > > Here’s a slightly amended version of your script:
>> > > 
>> > > tell application “BBEdit”
>> > >  tell front text window
>> > >replace "/\\*([^+]*?)\\*/" using "" options ¬
>> > > {search mode:grep, case sensitive:false, starting at top:true}
>> > >  end tell
>> > > end tell
>> > > 
>> > > The differences are:
>> > > 
>> > > - no parentheses () surrounding the whole find pattern because that 
>> becomes the first capture, which you use in the replacement pattern as ‘\1’.
>> > > 
>> > > - added parens around the inner part of the find pattern, in order to 
>> capture what’s between the JS comment markers.
>> > > 
>> > > -  if you needed to keep that outer parens capture for some other 
>> reason, then change the replacement pattern to “” (assuming that 
>> part stays the second parens-capture).
>> > > 
>> > > - I omitted the replace “%@“ line to keep this part of the script 
>> clear.
>> > > 
>> > > Using the script as I wrote it above
>> > > 
>> > > /* some commented stuff */ /*some more*/
>> > > 
>> > > And /* some more*/
>> > > 
>> > > is transformed in one step into 
>> > > 
>> > >  
>> > > 
>> > > And 
>> > > 
>> > > 
>> > > HTH
>> > > 
>> > >— Bruce
>> > > 
>> > > _bruce__van_allen__santa_cruz_ca_
>> > > 
>> > > 
>> > > 
>> > > 
>> > > 
>> > >> On Mar 17, 2023, at 3:04 AM, Mathias  wrote:
>> > >> 
>> > >> OK, so I'm working on an apple script to replace Localizable (apple) 
>> comments on the /* ... */ format to 
>> > >> 
>> > >> I got it working, but I'm using two commands because I couldn't 
>> figure the grep out... can this be simplified with only one "replace" ? 
>> > >> 
>> > >> pointers appreciated, script here:
>> > >> 
>> > >> tell application "BBEdit"
>> > >> tell front text window
>> > >> replace "(/\\*[^\\*]*\\*/)" using "" options ¬
>> > >> {search mode:grep, case sensitive:false, starting at top:true} 
>> > >> replace "(/\\*|\\*/)" using "" options {search mode:grep, case 
>> sensitive:false, starting at top:true} 
>> > >> replace "%@" using "%1$s" options {case sensitive:false, starting at 
>> top:true} 
>> > >> 
>> > >> end tell
>> > >> end tell
>> > >> 
>> > >> -- 
>> > >> This is the BBEdit Talk public discussion group. If you have a 
>> feature request or need technical support, please email "
>> sup...@barebones.com" rather than posting here. 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+un...@googlegroups.com.
>> > >> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/bbedit/65afd9cc-0a86-4821-b302-20b2948c3cdcn%40googlegroups.com
>> .
>> > > 
>> > > -- 
>> > > This is the BBEdit