LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-25-2011, 06:44 AM   #1
deefke
LQ Newbie
 
Registered: Jan 2011
Posts: 3

Rep: Reputation: 0
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.
 
Old 01-25-2011, 06:54 AM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
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.
 
Old 01-25-2011, 07:00 AM   #3
deefke
LQ Newbie
 
Registered: Jan 2011
Posts: 3

Original Poster
Rep: Reputation: 0
yes but I need to create the menu first

how shall i create the menu with the data from the csv file
 
Old 01-25-2011, 08:38 AM   #4
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
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
 
1 members found this post helpful.
Old 01-25-2011, 11:33 AM   #5
deefke
LQ Newbie
 
Registered: Jan 2011
Posts: 3

Original Poster
Rep: Reputation: 0
how should that help me?
 
Old 01-25-2011, 01:31 PM   #6
Snark1994
Senior Member
 
Registered: Sep 2010
Distribution: Debian
Posts: 1,632
Blog Entries: 3

Rep: Reputation: 346Reputation: 346Reputation: 346Reputation: 346
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!)
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash script help... menu to pick file from folder bfellenr Linux - Newbie 13 01-15-2011 03:30 PM
[SOLVED] bash read csv file daberkow Programming 4 04-28-2010 03:13 AM
Update csv file into mysql db via bash script xmrkite Linux - Software 4 01-13-2010 12:43 AM
[SOLVED] Need help create a bash script to edit CSV File imkornhulio Programming 13 02-05-2009 10:23 AM
bash script - remove header row from csv file pljvaldez Programming 5 08-30-2006 11:05 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:20 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration