LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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, 07: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, 07:54 AM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,424

Rep: Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823
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, 08: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, 09:38 AM   #4
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,424

Rep: Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823
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, 12:33 PM   #5
deefke
LQ Newbie
 
Registered: Jan 2011
Posts: 3

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

Rep: Reputation: 345Reputation: 345Reputation: 345Reputation: 345
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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 04:30 PM
[SOLVED] bash read csv file daberkow Programming 4 04-28-2010 04:13 AM
Update csv file into mysql db via bash script xmrkite Linux - Software 4 01-13-2010 01:43 AM
[SOLVED] Need help create a bash script to edit CSV File imkornhulio Programming 13 02-05-2009 11:23 AM
bash script - remove header row from csv file pljvaldez Programming 5 08-30-2006 12:05 PM


All times are GMT -5. The time now is 12:35 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration