The UNIX and Linux Forums  

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 here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
A challenging problem involving symbolic links. ibloom High Level Programming 2 03-24-2008 06:07 AM
Challenging Compare and validate question -- plus speed. madhunk Shell Programming and Scripting 25 05-26-2006 06:55 AM
A Challenging situation for the MODERATORS BAM UNIX for Dummies Questions & Answers 1 08-18-2002 10:12 AM
A Challenging Situation : i hope the moderators will respond to this problem.. BAM UNIX for Dummies Questions & Answers 2 07-08-2002 07:25 AM
Very Challenging Question! Need help bad! Sparticus007 UNIX for Advanced & Expert Users 1 01-07-2002 06:49 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-02-2008
Registered User
 

Join Date: Mar 2008
Posts: 1
Stumble this Post!
Challenging!! Help needed

Hi,

I have a script xyz.ksh which accpets two parameters the format of first one is :X_TABLENAME_Y and second one is a digit. I can extract a table name from that parameter and store it in a variable var_tblnm, so if i pass a parameter X_TABLE1_Y the value in var_tblenm is "TABLE1"
now i have a function library where i've set some paths..like

function_lib:
export A_TABLE1_B="/home/user1/table1.txt"
export A_TABLE2_B="/home/user1/table2.txt"
export A_TABLE3_B="/home/user1/table3.txt"

the data in the files is as below:
table1.txt: 1001,JOHN,1000.00
table2.txt: 1002,JEFF,2000.50
table3.txt: 1003,LINDA,3000.50

now ..my problem is as below:
when i run my script 'xyz.ksh' and pass parameters as below:
$xyz.ksh X_TABLE2_Y 3
here my result should be 2000.50.i.e the third column of the table2.txt
..what i'm doing is as below ..which is not working !

var_data=${A_"${var_tblnm}"_B}
var_amt= `cat $var_data |cut -d ',' -f$2
print "$var_amt"...


i'm not able to get the output as 2000.50...
Please help
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 03-02-2008
Moderator
 

Join Date: Dec 2003
Location: /dev/florida
Posts: 951
Stumble this Post!
The following small shell script should show you what you need to know:

Code:
#!/usr/bin/ksh

A_TABLE2_B="table2.txt"
echo $A_TABLE2_B

var_tbl="TABLE2"
# note the "\$"
var_data="\$A_${var_tbl}_B"
echo $var_data

#and now use eval to get actual data file name 
var_file=$(eval echo $var_data)
echo $var_file

#var_amt=`cat $var_file | cut -d',' -f$2`
#echo $var_amt
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 01:18 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0