The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
case statement c00kie88 Shell Programming and Scripting 2 10-12-2008 05:08 PM
If or Case Statement Ernst UNIX for Dummies Questions & Answers 1 09-24-2008 05:00 PM
case statement bkan77 Shell Programming and Scripting 5 09-11-2007 05:54 PM
Case Statement Zeta_Acosta Shell Programming and Scripting 19 04-06-2004 04:16 PM
case statement Bab00shka Shell Programming and Scripting 1 07-15-2002 05:31 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 12-09-2008
squrcles squrcles is offline
Registered User
  
 

Join Date: Nov 2008
Location: london/suburbia
Posts: 10
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 (permalink)  
Old 12-09-2008
manikantants manikantants is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 131
Kindly make it clear. What is the expected o/p on the above i/p?
Or what are you trying to achieve?
  #3 (permalink)  
Old 12-09-2008
squrcles squrcles is offline
Registered User
  
 

Join Date: Nov 2008
Location: london/suburbia
Posts: 10
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 (permalink)  
Old 12-18-2008
squrcles squrcles is offline
Registered User
  
 

Join Date: Nov 2008
Location: london/suburbia
Posts: 10
One of my highly skilled colleagues has pointed me in the direction of the select statement which is perfect for my requirements
  #5 (permalink)  
Old 12-18-2008
ahmad.diab's Avatar
ahmad.diab ahmad.diab is offline
Registered User
  
 

Join Date: May 2008
Location: Amman Jordan in MEA
Posts: 228
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 (permalink)  
Old 12-19-2008
squrcles squrcles is offline
Registered User
  
 

Join Date: Nov 2008
Location: london/suburbia
Posts: 10
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
Closed Thread

Bookmarks

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

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 05:25 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0