• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Delimit a File Containing Both Returns and Line Feeds
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Delimit a File Containing Both Returns and Line Feeds


  • Subject: Re: Delimit a File Containing Both Returns and Line Feeds
  • From: "Stockly, Ed" <email@hidden>
  • Date: Wed, 22 Aug 2018 23:14:34 +0000
  • Thread-topic: Delimit a File Containing Both Returns and Line Feeds

Something like this?


on open (itemList)

set newText to {}

repeat with this_file in itemList

tell application "Microsoft Word"

open (this_file as alias)

set myDoc to active document

set Acctinfo to content of text object of myDoc

display dialog ">>>" & Acctinfo & "<<<"

set allLines to paragraphs of Acctinfo

close myDoc saving no

end tell


set goodFields to {}

repeat with thisLine in allLines

if thisLine as text is not "" then

set the end of goodFields to thisLine as text

end if

end repeat

set AppleScript's text item delimiters to {tab}

set the end of newText to goodFields as text

end repeat

set newTextCount to count of newText

set AppleScript's text item delimiters to {return}

display dialog "Number of Fields After reduction= " & newTextCount & return &
newText as text

end open




From: AppleScript-Users
<applescript-users-bounces+ed.stockly=email@hidden<mailto:applescript-users-bounces+ed.stockly=email@hidden>>
 on behalf of Thomas Maffucci
<email@hidden<mailto:email@hidden>>
Reply-To: AppleScript Digest
<email@hidden<mailto:email@hidden>>
Date: Wednesday, August 22, 2018 at 3:22 PM
To: AppleScript Digest
<email@hidden<mailto:email@hidden>>
Subject: Delimit a File Containing Both Returns and Line Feeds

The objective of the following script to to go thru a given Folder of Text files
and take each line containing text and make just one line of tabbed text
(Which will later be inserted into an excel Spread Sheet). I have no problem
with
files containing Carriage returns or line feeds but have been unable to deal
with files contain both. I have attached 2 files
containing one file with returns

and one file containing returns and line feeds.

set source_folder to choose folder
tell application "Finder"
        set file_list to files in source_folder
end tell
repeat with this_file in file_list

        set Title to this_file as text
        set AppleScript's text item delimiters to "Macintosh
HD:Users:thomas:Desktop:test folder:"
        set Title1 to text item 2 of Title
        set AppleScript's text item delimiters to ""
        tell application "Microsoft Word"
                open (this_file as alias)
                set myDoc to active document
                select myDoc
                set Acctinfo to content of text object of selection
                                display dialog ">>>" & Acctinfo & "<<<"
                close documents saving no

        end tell
        set {lf, retx} to {ASCII character 10, ASCII character 13}
        set Multieol to false
        if Acctinfo contains lf and Acctinfo contains retx then
                display dialog "has both LF and retx"
                set eol to lf & retx
                set Multieol to true
        else
                if Acctinfo contains lf then
                        display dialog "has LF"
                        set eol to lf
                else
                        if Acctinfo contains retx then
                                display dialog "has return"
                                set eol to retx
                        else
                                display dialog "Has neither"
                        end if
                end if
        end if
        --if eol ≠ "Both" then
        if not Multieol then
                set AppleScript's text item delimiters to eol
                set allines to Acctinfo's text items
                set Numlnes to (count allines)
                display dialog "Number of lines pre reduction=" & Numlnes
        end if





        --if eol = "Both" then
        if Multieol then
                display dialog "File " & Title1 & " Has Both CR LF"
                set AppleScript's text item delimiters to eol
                set lnefield to text items of Acctinfo
                set AppleScript's text item delimiters to tab
                set goodline to lnefield as string
                display dialog "goodline=" & goodline
        else
                set Icount to 1
                set goodline to Title1 & tab
                set GoodFields to 0

                repeat Numlnes - 1 times
                        set AppleScript's text item delimiters to eol
                        set lnefield to text item Icount of Acctinfo
                        if lnefield ≠ "" then
                                set goodline to goodline & lnefield & tab
                                set GoodFields to GoodFields + 1


                        end if

                        set Icount to Icount + 1





                end repeat


                display dialog "Number of Fields After reduction=" & GoodFields

                display dialog "goodline=" & goodline
        end if
end repeat
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list
(email@hidden<mailto:email@hidden>)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden<mailto:email@hidden>
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

References: 
 >Delimit a File Containing Both Returns and Line Feeds (From: Thomas Maffucci <email@hidden>)

  • Prev by Date: Delimit a File Containing Both Returns and Line Feeds
  • Next by Date: Formatting Cell Values in Numbers 5.1
  • Previous by thread: Delimit a File Containing Both Returns and Line Feeds
  • Next by thread: Formatting Cell Values in Numbers 5.1
  • Index(es):
    • Date
    • Thread