trailing blank line in a text file

Olga olga at urbantimes.net
Wed Jul 21 03:05:58 UTC 2004


> On Tue, 2004-07-20 at 19:25, Robert Locke wrote:
>> On Tue, 2004-07-20 at 21:39, Olga wrote:
>> > No in vi and nano I do not see anything. But in gedit I see the
>> following
>> > (for example)
>> >
>> > 1 Mike
>> > 2 John
>> > 3 Adam
>> > 4
>> >
>> > The above is an example of what a file looks like with lines numbered.
>> > (numbers are not actually part of the file). I want the file to be
>> only 3
>> > lines long (as an example); however, what I get is 4 lines where line
>> 4 is
>> > an empty line. I can eliminate only using mc (F4). In nano, vim, vi it
>> is
>> > invisible, but in gedit (gui editor) it shows what I displayed above.
>> I
>> > can backspace after 4, it bring me to Adam, but when I save the file
>> and
>> > reopen it, the output is exactly the same as I am showing now (empty
>> line
>> > 4 stays).
>> >
>>
>> Let's try a different approach....
>>
>> After you save the file in whichever editor, can we confirm that it
>> actually has the "four lines" or really just has "three lines"?
>>
>> How about running "wc -l filename" and see how many lines it reports...
>> This will help to confirm for you whether the file truly has the blank
>> line, or is just a visual construct of the editor.
> ----
> You have a classic half full / half empty paradigm going here.
>
> The point is that a large number of editors will add a LF to the end of
> the file when it saves it. Thus, it doesn't put anything on the '4th'
> line in this example, it only makes sure that line 3 ends with a LF
> character. Whether you want to say that this file has 4 lines or 3 lines
> is really a subjective matter. It definitely has 3 lines, each of them
> ending with a LF character.
>
> Craig
>
Yes, I understand that. But what I want is for it to be 3 lines, because
the programs that I have that process those files will need to be changed
if I consider the file to be 4 lines long. And I was hoping it would be
easier for me to figure out how to eliminate trailing blank lines rather
than edit the programming code for it to work.





More information about the fedora-list mailing list