Re: GREP help: dig into the report of the cash register

2018-12-07 Thread ThePorgie
Ok, I think I've narrowed down the greedy over-run to only look between 
matching register numbers...So basically this should work regardless of 
varying number of item lines in your receipt.

Search:
t_fiscale (\d{4})(\d{2})(\d{2}) (\d+) (\d+)$(?s).*?TOTALE EURO 
+([0-9,]+).*?C\.F\. +([\w]+).*?N\.SCONTR\.FISCALE +\5

Replace:
\5\n\3/\2/\1\n\6\n\7\n\n

On Friday, December 7, 2018 at 4:03:26 AM UTC-5, m.osti wrote:
>
> Well ThePorgie, not sure to have understood your note but... now it's 
> perfect.
> thank you
>
> Il giorno giovedì 6 dicembre 2018 19:33:55 UTC+1, ThePorgie ha scritto:
>>
>> Right you are. I didn't notice that when I last tested. Try this:
>> t_fiscale (\d{4})(\d{2})(\d{2}) (\d+) (\d+)$(?:.*\n){1,8}?TOTALE EURO 
>> +([0-9,]+)(?:.*\n){1,3}?C\.F\. +([\w]+)
>>
>> and replace:
>> \5\n\3/\2/\1\n\6\n\7\n\n
>>
>> Note: I'm not sure how many items you can have listed on your receipt 
>> which causes me pause even with this grep string as 1 receipt with a long 
>> list will get skipped. I couldn't come up with a way to stop the greedy 
>> over-run if the string didn't contain the "C.F" line. If someone else 
>> notices something in this regard that I overlooked that would be great.
>>
>>
>> On Thursday, December 6, 2018 at 12:27:43 PM UTC-5, m.osti wrote:
>>>
>>> thank you for your concern. this GREP search is quite good: it get also 
>>> the sale(s) without CF that are unnecessary but I can just ignore them at a 
>>> fast glance.
>>>
>>> Il giorno mercoledì 5 dicembre 2018 18:20:28 UTC+1, ThePorgie ha scritto:

 I see you've got a script, but I like a puzzle... seems to work like 
 this.

 t_fiscale (\d{4})(\d{2})(\d{2}) (\d+) (\d+)$(?s).+?TOTALE EURO 
 +([0-9,]+).+?C\.F\. +([\w,]+)

 I used this with the extract option


 On Tuesday, December 4, 2018 at 8:14:34 AM UTC-5, m.osti wrote:
>
> Hello, every day when I have to close up my shop I get this report 
> from the cash register. I have the obligation to transmit some sales data 
> through a web page, and I have to insert one receipt at a time, sigh.
> Only sales that have the "C.F." are valid.
> In this case I need it in the order:
> the date
> the receipt number
> the total euro
> the alphanumeric part after C.F. for example ABCDEF12G34H567I which is 
> of 16 characters always in this order 6 alphabetic characters, 2 numbers, 
> 1 
> character, 2 numbers, 1 character, 3 numbers, 1 character.
>
> Now I copy them by hand and then I use a macro that I created in 
> KeyboardMaestro. Since there is a lot of data that I don't need, to speed 
> up I tried to extract only the necessary values through a GREP search, 
> but 
> I failed, failed, failed and after many attempts I decided to ask.
> If it were possible I would also like the date separator to be / 
> instead of -
>
> I'm going to put on the cash register closure below: the values I need 
> are in red.
> Thank you and sorry for my english.
> ciao from italy
>
> -m
>
> ---
>
> t_fiscale 20170422 0846 *1*
>   EURO  
> LENTI OFT 110,00
> MONTAGGIO LENTI20,00
> TOTALE EURO   *130,00*
> CONTANTE  130,00
> C.F.   *ABCDEF12G34H567I* 
> 
> CASSA:01
> *22-04-2017* 08:46
> N.SCONTR.FISCALE   1
> t_fiscale 20170422 0936 *2*
>   EURO  
> LENTI CONTATTO100,00
> TOTALE EURO   *100,00*
> CONTANTE  100,00
> C.F.   *ABCDEF12G34H567I* 
> 
> CASSA:01
> 22-04-2017 09:36
> N.SCONTR.FISCALE   2
> t_fiscale 20170422 1037 *3*
>   EURO  
> MONTATURE OFT 120,00
> LENTI OFT 120,00
> MONTAGGIO LENTI20,00
> TOTALE EURO   *260,00*
> CONTANTE  260,00
> C.F.   *LMNOPQ89R01S234T* 
> 
> CASSA:01
> 22-04-2017 10:37
> N.SCONTR.FISCALE   3
> t_fiscale 20170422 1055 4
>   EURO  
> IVA 22  8,00
> TOTALE EURO 8,00
> CONTANTE8,00
> 
> CASSA:01
> 22-04-2017 10:55
> N.SCONTR.FISCALE   4
> t_fiscale 20170422 1826 *5*
>   EURO  
> SOLUZIONI LAC  23,00
> TOTALE EURO23,00
> CONTANTE   *23,00*
> C.F.   *LMNOPQ89R01S234T* 
> 
> CASSA:01
> 22-04-2017 18:26
> N.SCONTR.FISCALE   5
> t_non fiscale 20170422 1843 1
>   NON FISCALE   
> RAPPORTO REPARTI "Z" 
>  PERIODICO 1 
> *(++ BELOW UNNECESSARY DATA ++)*
> DATA ULTIMO AZZERAMENTO  
>

Re: GREP help: dig into the report of the cash register

2018-12-07 Thread Christopher Stone
On 12/06/2018, at 13:44, Christopher Stone mailto:listmeis...@suddenlink.net>> wrote:
> Here's an updated script that produces cleaner output.
> From here I would probably turn the output into tab-delimited single lines.


Hey Marco,

The newest incarnation of the script (appended) produces output like this:

1   130,00  ABCDEF12G34H567I22-04-2017
2   100,00  ABCDEF12G34H567I22-04-2017
3   260,00  LMNOPQ89R01S234T22-04-2017
5   23,00   LMNOPQ89R01S234T22-04-2017

I can write another script that will parse these into variables that can be 
inserted into your web page.

Each pass will show a line item as processed like so:

[✓] 1   130,00  ABCDEF12G34H567I22-04-2017

If you set the windows of your web browser and BBEdit up just so, you can get 
realtime visual feedback on each pass.

--
Best Regards,
Chris


# Auth: Christopher Stone
# dCre: 2018/12/04 16:04
# dMod: 2018/12/07 02:43
# Appl: BBEdit
# Task: Extract Cash Register Info.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @BBEdit, @Extract, @Cash, @Register, @Info, 
@BBEdit-Talk
# Vers: 1.02


set AppleScript's text item delimiters to ""

tell application "BBEdit"
tell front text window's text

replace "^\\h+EURO\\h*\\n" using "" options {search mode:grep, case 
sensitive:false, starting at top:true}
replace "^\\h+$" using "" options {search mode:grep, case 
sensitive:false, starting at top:true}
replace "\\h+$" using "" options {search mode:grep, case 
sensitive:false, starting at top:true}
replace "\\n{2,}" using "\\n" options {search mode:grep, case 
sensitive:false, starting at top:true}
replace "^N\\.SCONTR\\.FISCALE.*" using "&\\n" options {search 
mode:grep, case sensitive:false, starting at top:true}
replace "\\A\\s+|\\s+\\Z" using "" options {search mode:grep, case 
sensitive:false, starting at top:true}

set docText to its text
set AppleScript's text item delimiters to linefeed & linefeed
set recordList to text items of docText

repeat with i in recordList
if contents of i does not contain "C.F." then
set contents of i to missing value
end if
end repeat

set recordList to (text of recordList) as text
set its text to recordList

replace "^(?>(?:(?!(?:t_fiscale|C\\.F\\.|\\d{2}-\\d{2}-\\d{4}|TOTALE 
EURO)).)*)$\\R?" using "" options {search mode:grep, case sensitive:false, 
starting at top:true}

replace "^t_fiscale" using "\\n&" options {search mode:grep, case 
sensitive:false, starting at top:true}
replace "\\A\\s+|\\s+\\Z" using "" options {search mode:grep, case 
sensitive:false, starting at top:true}

replace "^t_fiscale \\d{8} \\d{4} *" using "" options {search 
mode:grep, case sensitive:false, starting at top:true}
replace "^TOTALE EURO\\h+" using "" options {search mode:grep, case 
sensitive:false, starting at top:true}
replace "C\\.F\\.\\h*" using "" options {search mode:grep, case 
sensitive:false, starting at top:true}
replace "^(\\d{2}-\\d{2}-\\d{4})\\h+\\d{2}:\\d{2}" using "\\1" options 
{search mode:grep, case sensitive:false, starting at top:true}
replace "(?<=\\w)\\R(?=\\w)" using "\\t" options {search mode:grep, 
case sensitive:false, starting at top:true}
replace "^$\\R" using "" options {search mode:grep, case 
sensitive:false, starting at top:true}

select insertion point before it

end tell
end tell



-- 
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: GREP help: dig into the report of the cash register

2018-12-07 Thread m.osti
Well ThePorgie, not sure to have understood your note but... now it's 
perfect.
thank you

Il giorno giovedì 6 dicembre 2018 19:33:55 UTC+1, ThePorgie ha scritto:
>
> Right you are. I didn't notice that when I last tested. Try this:
> t_fiscale (\d{4})(\d{2})(\d{2}) (\d+) (\d+)$(?:.*\n){1,8}?TOTALE EURO 
> +([0-9,]+)(?:.*\n){1,3}?C\.F\. +([\w]+)
>
> and replace:
> \5\n\3/\2/\1\n\6\n\7\n\n
>
> Note: I'm not sure how many items you can have listed on your receipt 
> which causes me pause even with this grep string as 1 receipt with a long 
> list will get skipped. I couldn't come up with a way to stop the greedy 
> over-run if the string didn't contain the "C.F" line. If someone else 
> notices something in this regard that I overlooked that would be great.
>
>
> On Thursday, December 6, 2018 at 12:27:43 PM UTC-5, m.osti wrote:
>>
>> thank you for your concern. this GREP search is quite good: it get also 
>> the sale(s) without CF that are unnecessary but I can just ignore them at a 
>> fast glance.
>>
>> Il giorno mercoledì 5 dicembre 2018 18:20:28 UTC+1, ThePorgie ha scritto:
>>>
>>> I see you've got a script, but I like a puzzle... seems to work like 
>>> this.
>>>
>>> t_fiscale (\d{4})(\d{2})(\d{2}) (\d+) (\d+)$(?s).+?TOTALE EURO 
>>> +([0-9,]+).+?C\.F\. +([\w,]+)
>>>
>>> I used this with the extract option
>>>
>>>
>>> On Tuesday, December 4, 2018 at 8:14:34 AM UTC-5, m.osti wrote:

 Hello, every day when I have to close up my shop I get this report from 
 the cash register. I have the obligation to transmit some sales data 
 through a web page, and I have to insert one receipt at a time, sigh.
 Only sales that have the "C.F." are valid.
 In this case I need it in the order:
 the date
 the receipt number
 the total euro
 the alphanumeric part after C.F. for example ABCDEF12G34H567I which is 
 of 16 characters always in this order 6 alphabetic characters, 2 numbers, 
 1 
 character, 2 numbers, 1 character, 3 numbers, 1 character.

 Now I copy them by hand and then I use a macro that I created in 
 KeyboardMaestro. Since there is a lot of data that I don't need, to speed 
 up I tried to extract only the necessary values through a GREP search, but 
 I failed, failed, failed and after many attempts I decided to ask.
 If it were possible I would also like the date separator to be / 
 instead of -

 I'm going to put on the cash register closure below: the values I need 
 are in red.
 Thank you and sorry for my english.
 ciao from italy

 -m

 ---

 t_fiscale 20170422 0846 *1*
   EURO  
 LENTI OFT 110,00
 MONTAGGIO LENTI20,00
 TOTALE EURO   *130,00*
 CONTANTE  130,00
 C.F.   *ABCDEF12G34H567I* 
 
 CASSA:01
 *22-04-2017* 08:46
 N.SCONTR.FISCALE   1
 t_fiscale 20170422 0936 *2*
   EURO  
 LENTI CONTATTO100,00
 TOTALE EURO   *100,00*
 CONTANTE  100,00
 C.F.   *ABCDEF12G34H567I* 
 
 CASSA:01
 22-04-2017 09:36
 N.SCONTR.FISCALE   2
 t_fiscale 20170422 1037 *3*
   EURO  
 MONTATURE OFT 120,00
 LENTI OFT 120,00
 MONTAGGIO LENTI20,00
 TOTALE EURO   *260,00*
 CONTANTE  260,00
 C.F.   *LMNOPQ89R01S234T* 
 
 CASSA:01
 22-04-2017 10:37
 N.SCONTR.FISCALE   3
 t_fiscale 20170422 1055 4
   EURO  
 IVA 22  8,00
 TOTALE EURO 8,00
 CONTANTE8,00
 
 CASSA:01
 22-04-2017 10:55
 N.SCONTR.FISCALE   4
 t_fiscale 20170422 1826 *5*
   EURO  
 SOLUZIONI LAC  23,00
 TOTALE EURO23,00
 CONTANTE   *23,00*
 C.F.   *LMNOPQ89R01S234T* 
 
 CASSA:01
 22-04-2017 18:26
 N.SCONTR.FISCALE   5
 t_non fiscale 20170422 1843 1
   NON FISCALE   
 RAPPORTO REPARTI "Z" 
  PERIODICO 1 
 *(++ BELOW UNNECESSARY DATA ++)*
 DATA ULTIMO AZZERAMENTO  
21-04-2017
 
 CASSA:01
 22-04-2017 18:43
 N.SCONTR.NON FISC  1
   NON FISCALE   
 t_fiscale 20170422 1843 6
   RAPPORTO *Z*  
 CHIUSURA FISCALE
   DATI IN EURO  
 
 
  CORRISPETTIVI  
SCONTRINI
 
 CORRISP. GIORNALIERI
 1 234,00
 PROGR. CORRISPETTIVI
   123 456,78
 NOTE