Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

Looping through individual lines

Help
2008-06-11
2013-04-24
  • Paul Marshall
    Paul Marshall
    2008-06-11

    It's been a while since I was shell scripting regularly, but I thought that when the 'for' command was using a text files, it would loop through, 1 line at a time.

    I've got it to read the input file, but it's reading the whole file, instead of 1 line at a time ....
    Details below

    Any ideas?
    Is this is a limitation of UnxUtils?  Or is it my poor code?

    Input file (test.txt) like this:

    line1entry1    line1entry2    line1entry3
    line2entry1    line2entry2    line2entry3
    line3entry1    line3entry2    line3entry3

    Running script (test.sh) like this:

    export INPUTFILE="D:\\\\temp\\\\test.txt"
    echo INPUTFILE = $INPUTFILE

    for ENTRY in `cat $INPUTFILE`
    do
    echo ENTRY = $ENTRY
    done

    Results in:

    INPUTFILE = D:\temp\test.txt
    ENTRY = line1entry1
    ENTRY = line1entry2
    ENTRY = line1entry3
    ENTRY = line2entry1
    ENTRY = line2entry2
    ENTRY = line2entry3
    ENTRY = line3entry1
    ENTRY = line3entry2
    ENTRY = line3entry3