I want to read a large text data file, line by line. Sample code:
lines=0 while IFS=$' \t\n' do lines=$(($lines+1)) read val echo "lines=$lines val=$val" done < myfile
Problem: the loop reads past the end of the file !
$ wc -l myfile 41788 myfile
It goes fine at the beginning, I can see the data printed, but the loop does not stop after 41788. The counter goes on running with empty lines and I have to CTRL-C'it to stop.
Checked the data file, nothing special. size=5088370 bytes, the fields are tab separated (1).
$ file myfile myfile: ISO-8859 text, with CRLF line terminators
Any clue of what is going on here ? Did I miss something ?
(1) The fields are actually read with
read -a val, but I tried the simplified code above to reduce my MCWE.