My program should be able to work this way.
Below is the content of the text file named BookDB.txt The individual are separated by colons(:) and every line in the text file should serve as a set of information and are in the order as stated below.
Title:Author:Price:QtyAvailable:QtySold
Harry Potter - The Half Blood Prince:J.K Rowling:40.30:10:50 The little Red Riding Hood:Dan Lin:40.80:20:10 Harry Potter - The Phoniex:J.K Rowling:50.00:30:20 Harry Potter - The Deathly Hollow:Dan Lin:55.00:33:790 Little Prince:The Prince:15.00:188:9 Lord of The Ring:Johnny Dept:56.80:100:38 I actually intend to 1) Read the file line by line and store it in an array 2) Display it
However I have no idea on how to even start the first one. From doing research online, below are the codes which I have written up till now.
#!/bin/bash function fnReadFile() { while read inputline do bTitle="$(echo $inputline | cut -d: -f1)" bAuthor="$(echo $inputline | cut -d: -f2)" bPrice="$(echo $inputline | cut -d: -f3)" bQtyAvail="$(echo $inputline | cut -d: -f4)" bQtySold="$(echo $inputline | cut -d: -f5)" bookArray[Count]=('$bTitle', '$bAuthor', '$bPrice', '$bQtyAvail', '$bQtySold') Count = Count + 1 done } function fnInventorySummaryReport() { fnReadFile echo "Title Author Price Qty Avail. Qty Sold Total Sales" for t in "${bookArray[@]}" do echo $t done echo "Done!" } if ! [ -f BookDB.txt ] ; then #check existance of bookdb file, create the file if not exist else continue touch BookDB.txt fi "HERE IT WILL THEN BE THE MENU AND CALLING OF THE FUNCTION" Thanks to those in advance who helped!