Creating a dynamic case statement


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Creating a dynamic case statement
# 1  
Old 12-09-2008
Creating a dynamic case statement

I'm using the korn shell and trying to create a case statement from the contents of a file that is changed regularly,
each line of the file has three fields,
eg
track1 202.111.111.111 99
room7 222.111.222.333 76

I'm using awk to select each variable. I've been unable to figure out how to do this
does anyone have any suggestions on?

Last edited by squrcles; 12-09-2008 at 07:06 AM.. Reason: ammending for clarity
# 2  
Old 12-09-2008
Kindly make it clear. What is the expected o/p on the above i/p?
Or what are you trying to achieve?
# 3  
Old 12-09-2008
the i/p value is not relevant, all that is required is to make a case statement using the contents of a a file that is regularly changed

case "$var" in
track1)
commands;
;;
room7)
commands;
;;
*)
commands;
;;
esac

Last edited by squrcles; 12-09-2008 at 08:10 AM..
# 4  
Old 12-18-2008
One of my highly skilled colleagues has pointed me in the direction of the select statement which is perfect for my requirements
# 5  
Old 12-18-2008
Creating a dynamic case statement

try this:-
while read var1 var2 var3
do
case $var1 in
track1)
echo $var1 $var3 $var2
;;
room7)
commands;
;;
*)
commands;
;;
esac
done < INPUTFILE
# 6  
Old 12-19-2008
my final solution

cat > /var/tmp/list <<EOF
track1 202.111.111.111 99
room7 222.111.222.333 76
EOF
select i in `cat /var/tmp/list | awk '{print $1}`
do
echo `grep $i /var/tmp/list`
done
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Creating Dynamic Variables from a Flat File

Greetings all, Been trying to do my Googling and forum searches but can't seem to lock in on a solution. I have a script that parses a log and collects all the uniq events to a flat file. Some days might have 50 unique events, other days might have 75. (Hence my reference to dynamic.) ... (2 Replies)
Discussion started by: sjrupp
2 Replies

2. Shell Programming and Scripting

Dynamic case creation based on output list from a command

I am attempting to create a script that would allow me to list all the instances associated with a DB2 and then prompt the user to choose which one to issue the db2profile command against. I use the db2 command db2ilist to get a list of the instances for a particular server, but the number of... (7 Replies)
Discussion started by: slatoms
7 Replies

3. Red Hat

Dynamic case creation based on output list from a command

I am attempting to create a script that would allow me to list all the instances associated with a DB2 and then prompt the user to choose which one to issue the db2profile command against. I use the db2 command db2ilist to get a list of the instances for a particular server, but the number of... (1 Reply)
Discussion started by: slatoms
1 Replies

4. Web Development

MYSQL: Creating Dynamic Table Names 5.1

Hey everyone. Thanks for looking at this. I'm trying to create a table with the dynamic name of TableName + today's date. My variables are all happily created but the system chokes when I try to create the new table name example: Set @BFBW = CONCAT("BFBW", CURDATE()); Select @BFBW; ... (2 Replies)
Discussion started by: Astrocloud
2 Replies

5. Shell Programming and Scripting

Creating Dynamic Input or daa files

Hi, I got a requirement to automate the process. We have SLA files, there are some 80 SLA files comes from 1.30pm - 5.30pm. I was asked to write a script to check for the SLA files in the load directory, if the files come then we got to send the mail to the group, if the mails doesnt come... (1 Reply)
Discussion started by: afahmed
1 Replies

6. Programming

Dynamic Insert statement

I have a form , where i will put the values to a table. I wrote a insert statement for the same. Table structure is ename | character varying(30) | eadd | character varying(30) | eid | integer | sal | integer In the statements, i don't... (1 Reply)
Discussion started by: pritish.sas
1 Replies

7. Shell Programming and Scripting

need help with creating dynamic tcl displays

I'm fairly new to tcl scripting and could use a little help. I have a simple list file that will be of unknown size (somewhere between 10 to 20 names). I'd like to create a gui that has a checkbutton for each name in the list and a single action button that will do something for all the checkboxes... (0 Replies)
Discussion started by: scottwevans
0 Replies

8. Shell Programming and Scripting

creating a dynamic array

i want to create an array the array elements are populated depending upon the number of entries present in a data file The data file is created dynamically how to achieve the same thanks (1 Reply)
Discussion started by: trichyselva
1 Replies

9. Shell Programming and Scripting

creating dynamic shell script

Hello I am trying to create a dynamic ksh script and I have an issue. I have a script a.ksh and it has got the following lines (for example) #!/bin/ksh # trace mode +x : without trace -x : with trace set +xv echo hi, i am going to create a dynamic script now cat >> dynamic.ks <<EOF... (2 Replies)
Discussion started by: sundarkumars
2 Replies

10. Shell Programming and Scripting

creating a dynamic array in ksh

Hi, Is it possible to create a dynamic array in shell script. I am trying to get the list of logfiles that created that day and put it in a dynamic array. I am not sure about it. help me New to scripting Gundu (3 Replies)
Discussion started by: gundu
3 Replies
Login or Register to Ask a Question