How read a line of a file from C-shell?
Tom Parker
tparker at bierstadt.scd.ucar.edu
Tue Oct 23 10:48:21 AEST 1990
Thanks to all those that replied.
Several suggested using the C-shell $< function to read the lines from
stdin. This would work, except that I am submitting my C-shell script as
a job to a remote UNICOS system via NQS, and can't specify a stdin to my
script (the script is the job itself).
(By the way, I think that using `line` might be better than $<, since
then you can check for an EOF with $status).
One person suggested using 'cat' and setting IFS, but IFS is only in
Bourne shell.
The most feasible tip (so far) was to read the file using sed, e.g.:
set lines = `wc -l $file`
while ($i <= $lines[1])
set line = `sed -n ${i}p $file`
echo $i $#line $line
# (Process $line here)
@ i++
end
This seems to work well, as long as the file doesn't contain any
meta-characters. (I could put the `sed ...` in double quotes, but then I
can't tokenize the line).
Thanks to all that replied,
Tom
+---------------------------------------------------------------------------+
| Tom Parker |
| |
| Consulting Office Internet: TPARKER at NCAR.UCAR.EDU |
| Scientific Computing Division BITNET: TPARKER at NCARIO |
| Nat'l Center for Atmospheric Research Phone: (303) 497-1227 |
| Boulder, Colorado 80307 |
+---------------------------------------------------------------------------+
More information about the Comp.unix.questions
mailing list