insert carriage return every other line of a text file

I bet it won’t take you long to figure this one out and help a rookie at the same time:

I need to import a csv data file that has been word wrapped resulting in an extra carriage return every other line. I am using a freeware program, TextWrangler, to open the file but being new to this operating system I am not familar with apple script syntax. How do I insert a carriage return, line feed, backspace/delete every other line?

Thanks,

Terry

An example of my data file:

2,06/09/25,05:20:01,7.9,242,13,9.7,7.9,64,13,9.9,24.8,25.0,78,10,1011.7,12.0,-10
00000.000,-1000000.00000,0,0,0,0,0,0,0.0,0.0,336.6,12.53,3.60,0.68,7163,
2,06/09/25,05:35:01,7.8,237,14,9.2,7.8,58,14,9.2,24.6,24.9,79,13,1011.8,12.0,-10
00000.000,-1000000.00000,0,0,0,0,0,0,0.0,0.0,0.9,12.55,3.60,0.68,7072,
2,06/09/25,05:50:01,7.8,226,14,10.1,7.7,47,14,10.1,24.7,25.0,78,13,1012.0,12.1,-
1000000.000,-1000000.00000,0,0,0,0,0,0,0.0,0.0,345.0,12.55,3.63,0.68,7230,
2,06/09/25,06:05:01,8.4,228,12,10.3,8.4,49,12,10.4,24.7,25.1,78,14,1011.7,11.4,-
1000000.000,-1000000.00000,0,0,0,0,0,0,0.0,0.0,343.6,12.37,3.85,0.68,7249,
2,06/09/25,06:20:01,7.8,233,12,10.0,7.8,54,13,9.8,24.7,25.1,79,13,1011.8,12.1,-1
000000.000,-1000000.00000,0,0,0,0,0,0,0.0,0.0,358.7,12.52,6.46,0.68,7209,

Hi Terry;

Code Exchange is for finished scripts, not questions. I’ve moved you.

The usual way to do this in AppleScript is to read the text file directly, but if you’ve saved it in TextWrangler you can read that file into a variable in the script, unwanted returns and all. (I don’t understand what you say you want to do with the characters you list, and you don’t say which lines)

Then, assuming that the odd numbered paragraphs have a return you don’t want, this will create a new text variable N without them using your sample.


set T to "2,06/09/25,05:20:01,7.9,242,13,9.7,7.9,64,13,9.9,24.8,25.0,78,10,1011.7,12.0,-10
00000.000,-1000000.00000,0,0,0,0,0,0,0.0,0.0,336.6,12.53,3.60,0.68,7163,       
2,06/09/25,05:35:01,7.8,237,14,9.2,7.8,58,14,9.2,24.6,24.9,79,13,1011.8,12.0,-10
00000.000,-1000000.00000,0,0,0,0,0,0,0.0,0.0,0.9,12.55,3.60,0.68,7072,         
2,06/09/25,05:50:01,7.8,226,14,10.1,7.7,47,14,10.1,24.7,25.0,78,13,1012.0,12.1,-
1000000.000,-1000000.00000,0,0,0,0,0,0,0.0,0.0,345.0,12.55,3.63,0.68,7230,     
2,06/09/25,06:05:01,8.4,228,12,10.3,8.4,49,12,10.4,24.7,25.1,78,14,1011.7,11.4,-
1000000.000,-1000000.00000,0,0,0,0,0,0,0.0,0.0,343.6,12.37,3.85,0.68,7249,     
2,06/09/25,06:20:01,7.8,233,12,10.0,7.8,54,13,9.8,24.7,25.1,79,13,1011.8,12.1,-1
000000.000,-1000000.00000,0,0,0,0,0,0,0.0,0.0,358.7,12.52,6.46,0.68,7209,"

-- Assuming that the odd numbered paragraphs have a return you don't want:

set N to ""

repeat with k from 1 to count paragraphs of T
	if k mod 2 ≠ 0 then -- k is odd
		set N to N & text 1 thru -2 of paragraph k of T -- skip the final character, which is -1
	else
		set N to N & paragraph k of T
	end if
end repeat

-- returns five lines

Note, the easiest way to deal with CSV files is in Excel.

Hi,

Here’s another way to remove double returns.

set t to "a
b

c
d

e
f
"
ReplaceText(t, return & return, return)

on ReplaceText(t, s, r)
set user_tid to AppleScript’s text item delimiters
set AppleScript’s text item delimiters to {s}
set temp_list to text items of t
set AppleScript’s text item delimiters to {r}
set new_t to temp_list as string
set AppleScript’s text item delimiters to user_tid
return new_t
end ReplaceText

gl,