help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: preventing an empty last line in text files produced by dlmwrite


From: Benjamin Lindner
Subject: Re: preventing an empty last line in text files produced by dlmwrite
Date: Tue, 15 May 2007 08:00:57 +0200

> I tried grep -v ^$ <data.dat >data1.dat at the Octave command prompt, and
> only received an error message about syntax (invalid character "$" (ASCII
> 36)).

If you use this under windows, you must repeat the '^' character, as the caret 
is the escape character in windows' commander.
i.e. grep -v ^^$ <data.dat >data1.dat

Although i guess that this won't work, if I interpret your problem
correctly, since this will only filter out lines consisting only of a 
newline character, but NOT the last line after the ending newline.

you will not get around the last-newline problem, if you use 
dlmwrite(). You can do it manually of course like:

data = cat(2, (1:10).', (10:10:100).' );
fid = fopen( "test.data", "wb");  % mind the "b" under windows
% the all-but-last data rows, including newline
fprintf( fid, "%g %g\n", data(1:end-1,:).');
% the last row -> without newline!
fprintf( fid, "%g %g", data(end,:).' );
fclose( fid );

exchange with delimiters and printf formatters as you like.
Mind that fprints reads its numerical arguments columnwise, hence the
transpose.

benjamin
-- 
Psssst! Schon vom neuen GMX MultiMessenger gehört?
Der kanns mit allen: http://www.gmx.net/de/go/multimessenger


reply via email to

[Prev in Thread] Current Thread [Next in Thread]