# Write ASCII file without the last line

**URL:** <https://clarionhub.com/t/write-ascii-file-without-the-last-line/7916>\
**Category:** questions\
**Tags:** drivers\
**Created:** [February 15, 2025, 12:55pm UTC](https://clarionhub.com/t/write-ascii-file-without-the-last-line/7916 "2025-02-15T12:55:42Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![ademirpiva](https://clarionhub.com/user_avatar/clarionhub.com/ademirpiva/32/5557_2.png) [@ademirpiva](https://clarionhub.com/u/ademirpiva)\
**Post date:** [February 15, 2025, 12:55pm UTC](https://clarionhub.com/t/write-ascii-file-without-the-last-line/7916/1 "2025-02-15T12:55:42Z")

</div>

ASCII files are written with the last line of the file blank, there is an empty line after the last record.  
There is a company that receives these files and does not accept this last blank line, the file must have the last line with data.  
I am unable to save the file without this blank line.

---

<div class="post-metadata">

**Author:** ![PaulAttryde](https://clarionhub.com/user_avatar/clarionhub.com/paulattryde/32/3519_2.png) [@PaulAttryde](https://clarionhub.com/u/PaulAttryde)\
**Post date:** [February 15, 2025, 2:46pm UTC](https://clarionhub.com/t/write-ascii-file-without-the-last-line/7916/2 "2025-02-15T14:46:41Z")

</div>

Are you manually appending a CR/LF to every line or are you letting the driver do it?  
You could try writing the file like normal (except the last line), use /ENDOFRECORD driver string to change the terminator, then write the last line by itself.

---

<div class="post-metadata">

**Author:** ![ademirpiva](https://clarionhub.com/user_avatar/clarionhub.com/ademirpiva/32/5557_2.png) [@ademirpiva](https://clarionhub.com/u/ademirpiva)\
**Post date:** [February 15, 2025, 7:44pm UTC](https://clarionhub.com/t/write-ascii-file-without-the-last-line/7916/3 "2025-02-15T19:44:37Z")

</div>

I am not manually appending a CR/LF to each line, I am letting the driver do that.

I cannot use the driver string /ENDOFRECORD to change the terminator (/ENDOFRECORD only changes the record length, not the end of the file), all lines need to be of a fixed length in order to read the file, this company’s file reader is very limited.

---

<div class="post-metadata">

**Author:** ![CarlBarnes](https://clarionhub.com/user_avatar/clarionhub.com/carlbarnes/32/1859_2.png) [@CarlBarnes](https://clarionhub.com/u/CarlBarnes)\
**Post date:** [February 15, 2025, 7:57pm UTC](https://clarionhub.com/t/write-ascii-file-without-the-last-line/7916/4 "2025-02-15T19:57:36Z")

</div>

Use the DOS driver.

You’ll have to code ADD(File, Length) as the DOS driver does not Clip. Then ADD(File,2) with the 13,10 as the value for all but the last line.

---

<div class="post-metadata">

**Author:** ![PurpleEdge2214](https://clarionhub.com/user_avatar/clarionhub.com/purpleedge2214/32/5109_2.png) [@PurpleEdge2214](https://clarionhub.com/u/PurpleEdge2214)\
**Post date:** [February 16, 2025, 12:24am UTC](https://clarionhub.com/t/write-ascii-file-without-the-last-line/7916/5 "2025-02-16T00:24:42Z")

</div>

So you are creating an ascii file with fixed length records, terminated by a CRLF.

And, for this one company the last record shouldn’t have the CRLF terminator on the last record?

Do you have the String Theory add on template? If you do then I think you could edit the file in a few steps to remove the final record terminator?

If not, maybe the simplest approach is to set the record terminator to blank in your dct. The default terminator is CRLF ‘\<13,10\>’ - the help will explain how to do that, but ask here if you’re not sure how to do that.

Then, in your code for writing to the file, use …

```auto
...
Fil:Value12 = 'Some Value'

IF Company = BadCompany AND ThisIsTheLastRecord
  Fil:Value13 = 'Some other value' ! Don't add a CRLF to last record
ELSE
  Fil:Value13 = 'Some other value' & '<13,10>'
END
ADD(ExportFile)

```

---

<div class="post-metadata">

**Author:** ![vitesse](https://clarionhub.com/user_avatar/clarionhub.com/vitesse/32/837_2.png) [@vitesse](https://clarionhub.com/u/vitesse)\
**Post date:** [February 16, 2025, 12:29am UTC](https://clarionhub.com/t/write-ascii-file-without-the-last-line/7916/6 "2025-02-16T00:29:55Z")

</div>

the help for ENDOFRECORD says

```auto
DRIVER('ASCII', '/ENDOFRECORD = n [,m]' )

[EOR" =] SEND(file, 'ENDOFRECORD [= n [,m]]' )

Specifies the end of record delimiter.

n represents the number of characters that make up the end-of-record delimiter.

m represents the ASCII code(s) for the end-of-record delimiter, separated by commas. The default is 2,13,10, indicating 2 characters mark the end-of-record, namely, carriage return (13) and line feed (10). SEND returns the end of record delimiter.

```

so do as Paul says and SEND(file, ‘ENDOFRECORD = 0’) before writing the last line.

or do as Carl says and use the DOS driver

or do as I do and forget using any driver and use StringTheory.

so you have several options!

cheers

Geoff R

---

<div class="post-metadata">

**Author:** ![vitesse](https://clarionhub.com/user_avatar/clarionhub.com/vitesse/32/837_2.png) [@vitesse](https://clarionhub.com/u/vitesse)\
**Post date:** [February 16, 2025, 12:35am UTC](https://clarionhub.com/t/write-ascii-file-without-the-last-line/7916/7 "2025-02-16T00:35:16Z")

</div>

> [@PurpleEdge2214](#):
>
> Do you have the String Theory add on template? If you do then I think you could edit the file in a few steps to remove the final record terminator?

OK yes that’s yet another way to do it.

```auto
if not st.loadFile('myfile.txt') then <error>.
if st.endsWith('<13,10>') then st.adjustLength(-2).
st.saveFile('myFixedFile.txt')

```

an alternative to

```auto
if st.endsWith('<13,10>') then st.adjustLength(-2).

```

would be

```auto
st.clip('<13,10>')

```

which would simply take CR and LF chars off the end (regardless of order or quantity).

---

<div class="post-metadata">

**Author:** ![ademirpiva](https://clarionhub.com/user_avatar/clarionhub.com/ademirpiva/32/5557_2.png) [@ademirpiva](https://clarionhub.com/u/ademirpiva)\
**Post date:** [February 17, 2025, 6:29pm UTC](https://clarionhub.com/t/write-ascii-file-without-the-last-line/7916/8 "2025-02-17T18:29:37Z")

</div>

Thank you very much CarlBarnes.  
This is exactly what I needed, it worked perfectly.  
And it was very simple to implement in my system.

---

<div class="post-metadata">

**Author:** ![ademirpiva](https://clarionhub.com/user_avatar/clarionhub.com/ademirpiva/32/5557_2.png) [@ademirpiva](https://clarionhub.com/u/ademirpiva)\
**Post date:** [February 17, 2025, 6:45pm UTC](https://clarionhub.com/t/write-ascii-file-without-the-last-line/7916/9 "2025-02-17T18:45:38Z")

</div>

I appreciate all the answers, which are very useful and always add knowledge to all of us.

I don’t have the String Theory add-on template.

I tested it with DRIVER(‘ASCII’, ‘/ENDOFRECORD = n [,m]’ ), but I didn’t test it with parameter 0.

Thank you very much again.
