LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   bash script choice menu from csv file (https://www.linuxquestions.org/questions/linux-newbie-8/bash-script-choice-menu-from-csv-file-858515/)

deefke 01-25-2011 06:44 AM

bash script choice menu from csv file
 
Hi,

I don't have a lot experience in linux but 2 days ago I wrote my first script.

The script starts first a program I wrote earlier that collects specific data from 3 online csv files and write a summary csv file called /Tribalwars/request.csv . The seperator used is ;

the csv file looks like this but can be any number of rows (but not to many mostly 3 - 5)

Title1;tile2;...;title15;
B1;B2;...;B15
C1;C2;...;C15
D1;D2;...;D15

Now the next part of the script, and that is what I want to change, asks me to manually input some data I have to copy paste from the csv file just created.
I mean if i choose to continue to do my calculations for city 2, I need to copy-paste C1 for the first variable 'cityname' , copy-paste c2 for the second variable 'xxx',copy-paste C3 for the third variable 'yyy',copy-paste C15 for the fourth variable 'points'

Then it starts new calculations etc, witch only these variables.

Now could it be possible to make a menu from the csv file with only the according cells on the screen and that I only have to choose a row from the menu?

Thank you for reading all this.

grail 01-25-2011 06:54 AM

Maybe have a look at select ... it is used in bash to make menus (simple text based ones) and allows you to enter a number to select the item you want to do more with.

deefke 01-25-2011 07:00 AM

yes but I need to create the menu first

how shall i create the menu with the data from the csv file

grail 01-25-2011 08:38 AM

Here is something to get you going:
Code:

#!/bin/bash

PS3="Select wich row you would like: "

select opt in $(< csv_file)
do
    echo "Your choice is $opt"
    break
done


deefke 01-25-2011 11:33 AM

how should that help me?

Snark1994 01-25-2011 01:31 PM

Have you tried running the code? Grail was kind in giving you actual code to start you off. The "select" command is used for, among other things, making a menu. It makes sure that "opt" is one of the lines in csv_file, then you can run whatever code you like instead of the echo statement. You could try reading this tutorial - it also covers the "case" statement, so scroll down to read the things on select (though you might be interested in the case stuff too!)


All times are GMT -5. The time now is 04:16 AM.