Reformatting Text

Hi
I’m not sure how to approach this one - I have text in a file that is in this format repeating down the page with a line between each block; e.g.,

TD200026
HONDA
CIVIC_FERIO
GF-EK2
2000/03
AT
74K
207K

TD200026
HONDA
CIVIC_FERIO
GF-EK2
2000/03
AT
74K
207K

What I want to do is run a script that formats it like this with a tab between each word

TD200026 HONDA CIVIC_FERIO GF-EK2 2000/03 AT 74K 207K

Any suggestions greatly appreciated!!

set AppleScript’s text item delimiters to return
set oldList to text items of (read (choose file))

set AppleScript’s text item delimiters to tab
set newList to text items of oldList as string

Thanks for the suggestion - but it just seems to give a return-separated list

How about this then?

set oldList to (read (choose file))'s paragraphs
set AppleScript’s text item delimiters to tab
set newList to text items of oldList as string

Making progress!! It gives me the tabbed list - I just need to add the return character to separate each line like this:

TD200026 HONDA CIVIC_FERIO GF-EK2 2000/03 AT
TD200026 HONDA CIVIC_FERIO GF-EK2 2000/03 AT

Using regular expressions c/o the Satimage osax:

set s to "TD200026
HONDA
CIVIC_FERIO
GF-EK2
2000/03
AT
74K
207K

TD200026
HONDA
CIVIC_FERIO
GF-EK2
2000/03
AT
74K
207K

"

set s to change "([^\n])\n([^\n])" into "\1\t\2" in s with regexp
set s to change "\n+" into "\n" in s with regexp

Result:

"TD200026	HONDA	CIVIC_FERIO	GF-EK2	2000/03	AT	74K	207K
TD200026	HONDA	CIVIC_FERIO	GF-EK2	2000/03	AT	74K	207K
"

Notes:

  1. I’ve assumed text is linefeed-delimited (n); you’ll need to modify the regexes if it’s return-delimited (r).

  2. The Satimage osax isn’t Unicode-savvy, so if you’re dealing with Unicode text you’ll need to use something else. (AS sucks for text manipulation, doubly so for Unicode text.)

HTH

Vanilla AS solution (always set your text item delimiters back to the way they were!):

Jon


[This script was automatically tagged for color coded syntax by Convert Script to Markup Code]

Thanks to everyone who helped - it’s much appreciated. I think I’ve sorted it out to do what I want
Cheers