How read a line of a file from C-shell?

Steven M. List itkin at mrspoc.Transact.COM
Thu Oct 25 10:56:45 AEST 1990


tparker at bierstadt.scd.ucar.edu (Tom Parker) writes:

>Thanks to all those that replied.
> 
>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).

One small optimization:

    set -n "${i}p;${i}q" $file

This will cause sed to STOP when it has printed the line you want.
-- 
 +----------------------------------------------------------------------------+
 :                Steven List @ Transact Software, Inc. :^>~                  :
 :           Chairman, Unify User Group of Northern California                :
 :     {apple,coherent,limbo,mips,pyramid,ubvax}!itkin at guinan.Transact.COM    :



More information about the Comp.unix.questions mailing list