Reading input files by line using read command in shell scripting skips last line

前端 未结 5 545
日久生厌
日久生厌 2020-12-01 09:51

I usually use the read command to read an input file to the shell script line by line. An example code such as the one below yields a wrong result if a new line isn\'t inser

5条回答
  •  Happy的楠姐
    2020-12-01 10:27

    Below code with Redirected "while-read" loop works fine for me

    while read LINE
    do
          let count++
          echo "$count $LINE"
    
    done < $FILENAME
    
    echo -e "\nTotal $count Lines read"
    

提交回复
热议问题