0

I'm looping over a CSV:

Joe,12,23
Steve,45,87
Karen,34,142

CSV=data.csv

while IFS=',' read name foo bar
do
    for i in $(seq $foo $bar);
    do
        #things
    done;
done < $CSV

...but for some reason, seq is trying to divide the last number line ending \r

Benjamin Allison
  • 2,134
  • 3
  • 30
  • 55
  • You don't separate the variables in `read` with comma, you separate them with spaces: `read name foo bar` – Barmar Oct 21 '22 at 23:22
  • @Barmar sorry typed it wrong in the example. Edited. – Benjamin Allison Oct 21 '22 at 23:24
  • 2
    Your CSV file has CRLF line endings. Fix it with `dos2unix` – Barmar Oct 21 '22 at 23:26
  • Don't type your code into the question. Copy and paste your actual code, so that you don't introduce new errors and waste people's time. – Ken White Oct 21 '22 at 23:28
  • fwiw, probably would've been a bit more obvious had the actual error message been included in the post, namely: `seq: invalid floating point argument: ‘23\r’` ... the `\r` would have stood out more (than the `\r` at the end of your question) – markp-fuso Oct 21 '22 at 23:43
  • You can get `read` to trim the carriage return with `while IFS=$',\r' read ...` – Gordon Davisson Oct 22 '22 at 00:42

0 Answers0