Reading a file from within a C-shell script
Tom Parker
tparker at bierstadt.scd.ucar.edu
Thu Nov 15 08:24:53 AEST 1990
wes at uh.msc.umn.edu (Wes Barris) writes:
> Suppose one has a file containing names of other files like this:
>
> data.0001.rle
> data.0020.rle
> data.0025.rle
> data.0085.rle
>
> >From a C-shell script, I would like to, one-by-one, get the names out
> of this data file and do something with them like this:
>
> #!/bin/csh -f
> #
> #
> foreach file (my_file_list)
> echo $file
> process $file
> end
>
> Does anyone know how I do that?
>
Here is a C-shell script to read lines from a file
# Read lines from a file.
set noglob
set cmd = $0
set file = $1
if ("$file" == "") then
echo "Usage: $cmd:t file"
exit 4
endif
@ i = 1
set lines = `wc -l $file` || exit
while ($i <= $lines[1])
set a = `sed -n "${i}p;${i}q" $file`
echo $i $#a $a
@ i++
end
exit
More information about the Comp.unix.shell
mailing list