[Newbies] Re: reading lines from textfiles on Linux

Chris Kassopulo cpulo at earthlink.net
Tue May 16 10:57:37 UTC 2006


On Mon, 2006-05-15 at 18:55 -0700, Charles D Hixson wrote:
> OK.  Now:
> | fil lin n |
> fil    :=    FileStream fileNamed: 'aising/data/technologies.csv' .
> n    :=    0.
> [fil atEnd] whileFalse:
> [ lin := fil nextLine.
>   n := n + 1.
>   Transcript cr; show: 'lin '; show: n; show: ' = '; show: lin.
> ].
>  Transcript cr; show: 'normal end after '; show: n; show: ' lines'.
> 

Hi Charles,

I had a similar problem last week and Ron
showed how to use CrLfFileStream.

You have to test the end of line character.
You don't have to use a counter since the
whileFalse will loop through the whole file.

This works for me on linux whether the lines
end in lf or cr/lf.

| aFile myFile myStream line |
aFile := '/home/ckasso/logfiles-lf/ws000101.log'.
myFile := (aFile) asFileName.
Transcript clear.
myStream := CrLfFileStream fileNamed: myFile.
[ myStream atEnd ]
    whileFalse: [
        line := myStream upTo: Character lf.
        Transcript show: line; cr.].
myStream close.

You'll have to adapt it to your situation.

Chris





More information about the Beginners mailing list