[ILUG] Shell Programming: line by line file input?

Liam Bedford lbedford at wbtsystems.com
Mon Mar 13 10:56:34 GMT 2000


> -----Original Message-----
> From: ilug-admin at linux.ie [mailto:ilug-admin at linux.ie]On Behalf Of
> Cormac McClean
> 
> Hi,
> 
> Within a shell program (using bash), is it possible to read
> in a file line by line, e.g. if I have a file days.txt:
> 	Monday
> 	Tuesday
> 	Wednesday
> is it possible to read in each line separately and store the
> data in a variable?
> 	read day < days.txt
> gives me the first line, but how do I get it to read in the
> following lines, one at a time?
This one had me confused for ages:

while read LINE
do
        LINE1="${LINE2}"
        LINE2="${LINE}"
        FILENAME1=`echo ${LINE1} | sed -e "s/@.*$//g"`
        FILENAME2=`echo ${LINE2} | sed -e "s/@.*$//g"`
        if [ "${FILENAME1}" = "${FILENAME2}" ]; then
                cleartool describe -fmt "%d\t%u\t%n%Vn\n%c" ${LINE1}
                cleartool describe -fmt "%d\t%u\t%n%Vn\n%c" ${LINE2}
                echo ${FILENAME1}
                cleartool diff ${LINE1} ${LINE2}
        fi
done < ${OUTPUT}

That will read each line of ${OUTPUT} and put it into ${LINE} each time..

L.
---
Liam Bedford		| and if you spin your love around the 
lbedford at lbedford.org   | secrets of your dreams you may find your
(01) 4170153		| love is gone and is not quite what it seemed 




More information about the ILUG mailing list