Unix/Linux Go Back    


Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

Creating a dynamic case statement

Shell Programming and Scripting


Tags
shell script, shell scripting, unix scripting, unix scripting basics

Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 12-09-2008
squrcles squrcles is offline
Registered User
 
Join Date: Nov 2008
Last Activity: 6 March 2017, 1:19 PM EST
Location: london/suburbia
Posts: 38
Thanks: 21
Thanked 0 Times in 0 Posts
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 06:06 AM.. Reason: ammending for clarity
Sponsored Links
    #2  
Old Unix and Linux 12-09-2008
manikantants manikantants is offline
Registered User
 
Join Date: Feb 2008
Last Activity: 14 December 2009, 3:35 AM EST
Posts: 131
Thanks: 0
Thanked 1 Time in 1 Post
Kindly make it clear. What is the expected o/p on the above i/p?
Or what are you trying to achieve?
Sponsored Links
    #3  
Old Unix and Linux 12-09-2008
squrcles squrcles is offline
Registered User
 
Join Date: Nov 2008
Last Activity: 6 March 2017, 1:19 PM EST
Location: london/suburbia
Posts: 38
Thanks: 21
Thanked 0 Times in 0 Posts
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 07:10 AM..
    #4  
Old Unix and Linux 12-18-2008
squrcles squrcles is offline
Registered User
 
Join Date: Nov 2008
Last Activity: 6 March 2017, 1:19 PM EST
Location: london/suburbia
Posts: 38
Thanks: 21
Thanked 0 Times in 0 Posts
One of my highly skilled colleagues has pointed me in the direction of the select statement which is perfect for my requirements
Sponsored Links
    #5  
Old Unix and Linux 12-18-2008
ahmad.diab's Unix or Linux Image
ahmad.diab ahmad.diab is offline
Registered User
 
Join Date: May 2008
Last Activity: 7 August 2017, 4:42 AM EDT
Location: Amman, Jordan
Posts: 645
Thanks: 2
Thanked 19 Times in 19 Posts
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
Sponsored Links
    #6  
Old Unix and Linux 12-19-2008
squrcles squrcles is offline
Registered User
 
Join Date: Nov 2008
Last Activity: 6 March 2017, 1:19 PM EST
Location: london/suburbia
Posts: 38
Thanks: 21
Thanked 0 Times in 0 Posts
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
Sponsored Links
Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Dynamic Insert statement pritish.sas Programming 1 07-30-2009 03:37 PM
need help with creating dynamic tcl displays scottwevans Shell Programming and Scripting 0 10-24-2008 01:09 PM
creating a dynamic array trichyselva Shell Programming and Scripting 1 07-10-2008 09:13 AM
creating dynamic shell script sundarkumars Shell Programming and Scripting 2 02-13-2008 10:28 AM
creating a dynamic array in ksh gundu Shell Programming and Scripting 3 03-09-2005 02:26 PM



All times are GMT -4. The time now is 10:57 AM.