filename = 'test.txt'
tofilename = 'test2.txt'
lastchar = 0
extrachar = ""
line = ""
IF STREAM(filename, 'C', 'OPEN READ') == 'READY:' THEN DO
IF STREAM(tofilename, 'C', 'OPEN WRITE REPLACE') \== 'READY:' THEN DO
SAY STREAM(tofilename, 'D')
CALL STREAM filename, 'C', 'CLOSE'
RETURN
END
total = CHARS(filename)
DO WHILE total > 0
IF extrachar == "" THEN char = CHARIN(filename, , 1)
ELSE DO
char = extrachar
extrachar = ""
END
total = total - 1
IF char == "0A"x | char == "0D"x THEN DO
IF lastchar == ',' THEN DO
offset = LASTPOS(',', line)
IF offset > 1 THEN DO
line = STRIP(LEFT(line, offset - 1), 'T')
END
line = line || " "
lastchar = 0
IF total > 0 & char == "0D"x THEN DO
char = CHARIN(filename, , 1)
IF char \== "0A"x THEN DO
extrachar = char
END
ELSE DO
total = total - 1
END
END
END
ELSE DO
IF line \== "" THEN CALL LINEOUT tofilename, line
lastchar = 0
line = ""
END
END
ELSE DO
line = line || char
IF char \== ' ' & char \== "09"x THEN lastchar = char
END
CATCH NOTREADY
SAY STREAM(tofilename, 'D')
line = ""
END
IF line \== "" THEN CALL LINEOUT tofilename, line
CALL STREAM filename, 'C', 'CLOSE'
CALL STREAM tofilename, 'C', 'CLOSE'
END
ELSE SAY STREAM(filename, 'D')
RETURN |