On 12/04/2018, at 04:19, m.osti <[email protected] <mailto:[email protected]>> 
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.


Hey M.,

This is a bit of a sticky problem, so I'm not surprised you had problems when 
relying on grep alone.

Run this AppleScript from the Applescript Editor against your register tape in 
BBEdit.

I believe I've extracted the relevant data from the tape.  If so then we need 
another pass to get just the values you want.

>From there it shouldn't be hard to pop those values into Keyboard Maestro 
>variables for insertion into your web page.

--
Best Regards,
Chris

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

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 "\\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}
        
        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
"[email protected]" rather than posting to the group.
Follow @bbedit on Twitter: <https://www.twitter.com/bbedit>
--- 
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/bbedit.

Reply via email to