Re^2: csh: still trying to read file

Michael Stanley jms at hcx.uucp
Tue Apr 4 13:43:41 AEST 1989


In article <2239 at star.cs.vu.nl>, maart at cs.vu.nl (Maarten Litmaath) writes:
> jms at hcx.uucp (Michael Stanley) writes:
> \...  Keep a variable which
> \is the number of the next line you plan to read.  Each time you read
> \a line, you can add one to it.  Now, knowing the line number, how do I
> \get that line from a file...  Try this:
> 
> \	set file_name = "TESTFILE"
> \	set line_no = "5"
> \	set line_buff = `sed -n "${line_no}p" $file_name`
> \	echo $line_buff
> 
> So for every line you must skip n - 1 lines first!
> Furthermore: how are you going to distinguish eof from empty lines?

Hey, I never SAID it was a GOOD solution.  The n-1 lines isn't pretty,
but I didn't know a better way off the top of my head, and it looked
like no one else was responding.  Someone did post an improvement
which prevented reading the lines FOLLOWING the line to capture.  So
I learned something in the process, and I thought that was great.

Also, I realized when I wrote it that the code couldn't stand alone, or,
in other words, that it would be necessary to determine the number of
lines in the file to prevent the attempt to read past the EOF.  However,
that wasn't the question, so I didn't answer that.  However, if you are
curious, the 'wc' command will supply the number of lines in a file.

> 
> \...
> \	setenv PATH "/bin:/usr/bin:/usr/local:~yourid/bin"
> 
> By this scheme any subcommand that invokes execvp() one way or the other,
> will `fail': the environment variable is LITERALLY set to the above, that is,
> including the tilde, and the directory "~yourid" isn't the directory you
> intended to include (and it probably doesn't exist).
> Use `set path=(...)' or `setenv PATH ...$HOME/bin'. RTFM.
> Furthermore "~yourid/bin" ("~/bin", for insiders :-) should be the FIRST
> directory in your PATH.
> -- 

Actually, you are wrong.  You are right in that, the ~ isn't expanded
when added to the environment, but it still seems to find my bin
directory and execute the commands in it.  If your csh won't do this,
I'm sorry, but every csh I've ever used will.

Finally, if I thought that my every posting would recieve such criticism,
I probably wouldn't post.  Back off a bit, ok?  I just supplied a solution
WHICH WORKS when none others were available.


	Michael Stanley		(...!uunet!harris.cis.ksu.edu!jms at hcx)



More information about the Comp.unix.questions mailing list