Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!sharkey!atanasoff!deimos.cis.ksu.edu!cveg!hcx!jms From: jms@hcx.uucp (Michael Stanley) Newsgroups: comp.unix.questions Subject: Re: csh: still trying to read file Summary: csh: how to read a file line by line Keywords: csh C shell read programming unix Message-ID: <2156@cveg.uucp> Date: 1 Apr 89 07:41:25 GMT References: <2130@pikes.Colorado.EDU> Sender: netnews@cveg.uucp Organization: College of Engineering, University of Arkansas, Fayetteville Lines: 43 In article <2130@pikes.Colorado.EDU>, pklammer@pikes.Colorado.EDU (Peter Klammer) writes: > Thank you all; yes, I know $< can accept a line from stdin. > But what I want is to read a file a line at a time in the Well, I'm surprised no one has answered this one by now. My answer may not be the best solution, but it WILL work. 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 As usual, I'm lazy and haven't tested this, but I've done stuff like this before. It isn't pretty but it'll work. > Another csh mystery (at least until I get my book, maybe): if I prepare > a csh script file (with the mandatory "#" on line 1) and chmod +x it, > and then invoke it from a subdirectory, it is run from my HOME directory! If I understand what you are asking, you want to be able to run your new command from any directory as if it were a system command. The best way to do this is to create a directory off YOUR main directory (call it 'bin') and add that directory to your PATH environment variable (which SHOULD be set in your .login file as this is a login parameter which is usually set once and then left alone). An example command to set your PATH from your .login file might be as follows (watch out because every UNIX system seems to have a slightly different set of directories for their system binaries). But over all it should be close to this: setenv PATH "/bin:/usr/bin:/usr/local:~yourid/bin" Notice the important part '~yourid/bin'. This says that after all the system directories are searched to locate a command, YOUR 'bin' directory will be searched. Hope this helps and isn't too vague. Michael Stanley (...!uunet!harris.cis.ksu.edu!jms@hcx)