next up previous 405
Next: Reading tabular data
Up: Dealing with Files
Previous: Writing a script within a script


Reading lines from a text file

There is no simple file reading facility in the C-shell. So we call upon awk again.

     set file = `awk '{print $0}' sources.lis`
Variable file is a space-delineated array of the lines in file sources.lis. More useful is to extract a line at a time.

     set text = `awk -v ln=$j '{if (NR==ln) print $0}' sources.lis`
where shell variable j is a positive integer and no more than the number of lines in the file, returns the $j$th line in variable text.



next up previous 405
Next: Reading tabular data
Up: Dealing with Files
Previous: Writing a script within a script

C-shell Cookbook
Starlink Cookbook 4
Malcolm J. Currie
2006 November 26
E-mail:starlink@jiscmail.ac.uk

Copyright © 2013 Science and Technology Facilities Council