Problem with reading file and executing other stuffs?

2007-11-01 Thread Horinius
I've been struggling with the following code of reading a text file (test.txt) and counting the number of lines. Well, I know there're simpler method to count the number of lines of a text file, but that's not the point of this post. __ n=0 cat test.txt | while read line do n=$(

Re: Problem with reading file and executing other stuffs?

2007-11-02 Thread Horinius
Paul Jarc wrote: > > Read entry E4 in the bash FAQ: > http://tiswww.case.edu/php/chet/bash/FAQ > OK, I see, the problem comes from use of pipeline which triggers creation of subprocess (why should they do so? -- no need to answer this question :p ) I've read several times that section but I'm

Re: Problem with reading file and executing other stuffs?

2007-11-02 Thread Horinius
Paul Jarc wrote: > > If you're reading from a regular file, you can just eliminate the > useless use of cat: > while read line; do ...; done < test.txt > Oh yes! This is a lot better and syntactically simpler than using the file descriptor 6 (which nevertheless is also a working solution). I

Re: Problem with reading file and executing other stuffs?

2007-11-02 Thread Horinius
Hugh Sasse wrote: > > On Fri, 2 Nov 2007, Horinius wrote: >> I've found that if the last line isn't terminated by a new-line, that >> line >> can't be read. This seems to be a very common error and I've seen it in >> other commands. > &

Re: Problem with reading file and executing other stuffs?

2007-11-08 Thread Horinius
Hugh Sasse wrote: > > And vi warns about it in a similar way to ed. > > Again, what problem are you trying to solve, if any? > I'm doing some processing in a big file which is well formatted. It's sort of a database table (or a CVS file if you like). Every line contains a unique element th

Re: Problem with reading file and executing other stuffs?

2007-11-12 Thread Horinius
Hugh Sasse wrote: > > OK, if it is in fields, like /etc/passwd, then awk is probably more > suited to this problem than reading it directly with shell script. > > If it has some delimited keyword, but each line has variable structure, > then you'd be better using sed. > The files contain some