![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
|||
|
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 |
| Forum Sponsor | ||
|
|
|
|||
|
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
|
|||
| Google The UNIX and Linux Forums |