Delimit a File Containing Both Returns and Line Feeds
Delimit a File Containing Both Returns and Line Feeds
- Subject: Delimit a File Containing Both Returns and Line Feeds
- From: Thomas Maffucci <email@hidden>
- Date: Wed, 22 Aug 2018 18:22:44 -0400
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
I want to
Move all
Lines to
One tabbed text
line
Account Number 8794321079-0055
Confirmation Number AXwe3786977
Confirmation Date 12/13/2010
Joe Multiline
Dob: 12/28/08
{\rtf1\ansi\ansicpg1252\cocoartf1504\cocoasubrtf830
\cocoascreenfonts1{\fonttbl\f0\fswiss\fcharset0 Helvetica;\f1\fnil\fcharset0
Verdana;}
{\colortbl;\red255\green255\blue255;}
{\*\expandedcolortbl;;}
\margl1440\margr1440\vieww9000\viewh8400\viewkind0
\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\pardirnatural\partightenfactor0
\f0\fs24 \cf0 \
I want to\
\
\
Move all\
\pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\pardirnatural\partightenfactor0
\f1\fs20 \cf0 Lines to
\f0\fs24 \
\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\pardirnatural\partightenfactor0
\cf0 \
One tabbed text\
\
line\
\
\
Account Number 8794321079-0055\
\
\
Confirmation Number AXwe3786977\
\
\
\pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\pardirnatural\partightenfactor0
\f1\fs20 \cf0 Confirmation Date 12/13/2010\
\
\
Joe Multiline\
\
\
DOB: 12/28/08
\f0\fs24 \
}
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)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden