Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

In a windows REXX, How to suppress the last "CRLF" in a TXT file.

133 views
Skip to first unread message

ebmso...@ebm.fr

unread,
Mar 20, 2013, 7:58:05 AM3/20/13
to
hello,

I use REGINA on Windows and have build some Rexx.
I have one doing followings:
Read several txt files.
Test the content of each
Generate a new file within the results.
My problem is:
I need to suppress the last CRLF in the last line of my new TXT file.
Thanks in advance for your help and advices.

Jean-Louis Faucher

unread,
Mar 20, 2013, 8:17:30 AM3/20/13
to
> I need to suppress the last CRLF in the last line of my new TXT file.
>

Maybe with charout ?
Tested under win7 with regina 3.7 :
call lineout "myfile", "line1"
call lineout "myfile", "line2"
call charout "myfile", "last line"

Binary dump of myfile :
00000000 6C 69 6E 65 31 0D 0A 6C 69 6E 65 32 0D 0A 6C 61 line1..line2..la
00000010 73 74 20 6C 69 6E 65 st line

ebmso...@ebm.fr

unread,
Mar 20, 2013, 8:47:32 AM3/20/13
to
Hi
Thanks for your answer.
The problem is that the enw file is generated depending on the results of the tests done on several files. Thereofre, i have no idea on how many line the new file will content and no idea also on each lines.
Exmaple:
File1.txt, content Company, name, email,
File2.txt; content Company, name,
File3.txt, content Company, name, email
REXX:
Statut_Email = Word(line,3)
If Statut_email <> " " then do
Email_list = Name_Email
File_out=liste_mail
Call Lineout file_out,Email_list
Here I can have 50 file.txt to be tested then one liste_mail file generated.
And I need to suppress the CRLF in the liste_mail file.
Thanks for your help.

Glenn Knickerbocker

unread,
Mar 20, 2013, 9:50:22 AM3/20/13
to
On Wed, 20 Mar 2013 05:47:32 -0700 (PDT), ebmso...@ebm.fr wrote:
>The problem is that the enw file is generated depending on the results of
>the tests done on several files. Thereofre, i have no idea on how many
>line the new file will content and no idea also on each lines.

You can use charout() to write each line and lineout() to write the line
feeds in between. You'd need to keep a flag to show whether you have
written the *first* line to each file or not.

OutLine: Procedure Expose writeflag.
Parse Arg file, line
If writeflag.file = 1 Then Call LineOut file
Else writeflag.file = 1
Call CharOut file, line
End

You'd have to make sure to expose that WRITEFLAG. stem in all your
procedures. If you're using ooRexx, you could avoid that complication by
using the .local object instead of variables to hold the flags:

OutLine:
If .local~hasIndex('writeflag.'Arg(1)) Then Call LineOut Arg(1)
Else .local~put(1, 'writeflag.'Arg(1))
Call CharOut Arg(1), Arg(2)
Return

�R / Darla: Leftovers aren't the mark of a man. \ www.bestweb.net/~notr
Andrew Reid: Actually, they are, because that's how men's shirts button.

U. Zinngrebe

unread,
Mar 20, 2013, 10:21:25 AM3/20/13
to
ebmso...@ebm.fr wrote:

> ... I have no idea on how many lines the new file will contain ...

> REXX:
> Statut_Email = Word(line,3)
> If Statut_email <> " " then do
> Email_list = Name_Email
> File_out=liste_mail
> Call Lineout file_out,Email_list
> Here I can have 50 file.txt to be tested then one liste_mail file
> generated. And I need to suppress the CRLF in the liste_mail file.

If liste_mail is not too large, then changestr() can be used to remove all
CRLF (see reference, chapter 7.4.13)

If converting CR and LF into space is ok then I would prefer translate(),
because there is no need to close the gaps created by removing bytes from
liste_mail.

As Jean-Louis said, writing out the file must be done with charout()
because lineout() appends CRLF.

Cheers, Uli




Glenn Knickerbocker

unread,
Mar 20, 2013, 10:41:52 AM3/20/13
to
On 3/20/2013 9:50 AM, I wrote:
> You can use charout() to write each line and lineout() to write the line
> feeds in between. You'd need to keep a flag to show whether you have
> written the *first* line to each file or not.

I guess you might also want to check for existence of the file if you
haven't written to it yet, and write a new line if it exists, since you
won't expect it to end with a line feed. In ooRexx, you can use the
SysFileExists function:

OutLine:
If .local~hasIndex('writeflag.'Arg(1)) Then Call LineOut Arg(1)
Else Do
If SysFileExists(Arg(1)) then Call LineOut Arg(1)
.local~put(1, 'writeflag.'Arg(1))
End
Call CharOut Arg(1), Arg(2)
Return

ŹR

Swifty

unread,
Mar 20, 2013, 11:05:58 AM3/20/13
to
On 20/03/2013 14:41, Glenn Knickerbocker wrote:
> I guess you might also want to check for existence of the file if you
> haven't written to it yet

I'd use this technique. If the files was new, then I'd use charout() to
add the line. Otherwise I'd use charout to append:

'0D0A'x || line

... to the end of the file.

There's one unpleasant catch to having files without the trailing
CRLF... if you append to the file, then it's all too easy to end up
concatenating the original last line and your new line.

I've made this mistake in the last 24 hours when I edited the data file
used by a process, and forgot to add the "newline" at the end. My
program concatenated the next new line onto the end of my edited last line.

--
Steve Swift
http://www.swiftys.org.uk/

LesK

unread,
Mar 20, 2013, 4:46:45 PM3/20/13
to
I don't deal with files at such a granular level, so what's the subtle
point behind not writing CRLF at the end of the last line of a file?

I use ooRexx and the following little routine seems to work fine and THE
is quite happy to show me the file:

attendee: procedure
parse arg line
joined_file=rexxla_config('ATTENDEES')
.stream~new(joined_file)~~lineout(line)~close
Return

Les

--

Les (Change Arabic to Roman to email me)

Swifty

unread,
Mar 21, 2013, 2:24:05 AM3/21/13
to
On 20/03/2013 20:46, LesK wrote:
> what's the subtle point behind not writing CRLF at the end of the last
> line of a file?

I can't speak for the OP, but I find myself removing the trailing CRLF
on occasions.

In my case, it is mostly for cosmetic reasons. With the trailing CRLF,
then editors tend to display a trailing null line (it is more obvious if
the editor is also displaying line numbers)

No doubt editors could suppress that trailing null line, but then you'd
have no visual clue whether or not there is a trailing line-end.

It's obviously not a major influence in my life as I'm struggling to
find other examples.
0 new messages