shell script: read in values from text file

before i forget how to do this again assuming test.txt contains a number on each line, ie.

123
324
45656

heres a couple of simple ways to read from the file and so stuff in a shell script

#!/bin/bash
INFILE=test.txt
OUTFILE=out.xml
for i in $(cat $INFILE) ; do
     #do some stuff
     echo item: $i
done

or use

while read line
    do
        echo $line;
done < $INFILE

(echo "</oai_dc:dc>" >> $OUTFILE )

Justin Kelly

Justin Kelly

Web Developer, Business Analytics, Data Engineer specialising in PHP, ReactJS, Tableau, AWS RedShift and Matillion ETL

Based in Melbourne, Australia

Feel free to contact me justin@kelly.org.au or _justin_kelly

Leave a comment

Name Notify me of replies by email.