Skip to content
Advertisement

Bash: While-read loop skips the last line of comma-separated text file

I am trying to read some comma-separated data from a text file, parse it and calculate average of column-5. The input is in the following form:

JavaScript

I am using the following script for this:

JavaScript

The problem with the script is that it does not read / parse the last line of the text. What can I do about that?

Also, every time I run the script, the value of hours keeps on increasing (probably the previous value is stored). How can the value be defaulted to zero everytime the script runs?

TIA

Advertisement

Answer

The following code worked for me:

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement