Let’s imagine we have a budget document: budget.txt
The exercise is to calculate the sum column for every product in the month, also to calculate totals in the last row. You may try to do it in a shell. How shall it work?
- a program/script shall take a parameter with the filename (not to be hardcoded in the body)
- do the needful
- print output to a screen
- if there’s an error in the data file somewhere, the program/script shall print it on a screen and terminate.
For the bash script, you may try with awk and bc commands.
I have created a shell script
#!/bin/bash
echo -n " Please write the file name:"
read file
awk '{print $0}' $file