Challenging!! Help needed


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Challenging!! Help needed
# 1  
Old 03-02-2008
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
# 2  
Old 03-02-2008
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

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Challenging scenario

Hi, My input file contains 1,2 2,4 3,6 4,9 9,10 My expected output is 1,10 2,10 3,6 4,1 9,10 (6 Replies)
Discussion started by: pandeesh
6 Replies

2. Shell Programming and Scripting

simple but challenging ignore case

Folks - I found this code on the forums to extract a paragraph for a matching pattern but I don't know how to make it ignore case. grep "-ip" is not an option for me as I am on SUSE LINUX. Thanks for ur help. I run this script as below: grep_para.ksh sqlstate < logfile "The end result... (2 Replies)
Discussion started by: beowulfkid
2 Replies

3. Shell Programming and Scripting

Challenging Awk array problem

Hi, I rather have a very complicated awk problem here, at least to me. I have two files. File 1: 607 687 174 0 0 chr1 3000001 3000156 -194195276 - L1_Mur2 LINE L1 -4310 1567 1413 1 607 917 214 114 45 chr1 3000237 ... (19 Replies)
Discussion started by: polsum
19 Replies

4. UNIX for Advanced & Expert Users

Very Challenging :Copy files in Multiple Threads

Hello all, I asked this in the basic Unix forum got no answer since one week. So I believe this is an advanced level question hence posting it here. Any suggestions welcome. I have a directory of files of varying sizes. I want to copy all these files in n number of threads to... (2 Replies)
Discussion started by: samoo
2 Replies

5. Shell Programming and Scripting

help needed with creating challenging bash script with creating directories

Hi, Can someone help me with creating a bash shell script. I need to create a script that gets a positive number n as an argument. The script must create n directories in the current directory with names like map_1, map_2 etcetera. Each directory must be contained within its predecessor. So... (7 Replies)
Discussion started by: I-1
7 Replies

6. Shell Programming and Scripting

Need help with this challenging code....

Hello All, I am new to this forum, and the reason I came here is to seek solution from the experts. I have written following wrapper script, it was running fine from past couple of months, until last week. When one of the function in the script which suppose to login through ssh to the... (2 Replies)
Discussion started by: tajdar
2 Replies

7. Shell Programming and Scripting

Very Challenging Problem. Please read fully.

Hi, This is the Third thread i'm putting here for the same problem. :( Actually, i'm trying a script like this.. but its taking a long time.. about 3 days to complete fully.. #!/bin/ksh if then exit 1 fi while read i do while read j do field7=`echo $j|cut -d "|"... (12 Replies)
Discussion started by: RRVARMA
12 Replies

8. Shell Programming and Scripting

Challenging Compare and validate question -- plus speed.

I have a tab delimited HUGE file (13 million records) with Detail, Metadata and Summary records. Sample File looks like this M BESTWESTERN 4 ACTIVITY_CNT_L12 A 3 M AIRTRAN 4 ACTIVITY_CNT_L12 A 3 D BESTWESTERN FIRSTNAME LASTNAME 209 N SANBORN AVE D BESTWESTERN FIRSTNAME LASTNAME 6997... (25 Replies)
Discussion started by: madhunk
25 Replies

9. UNIX for Dummies Questions & Answers

A Challenging situation for the MODERATORS

Well, I hope this way you will respond to my inquiries. I have 4 unix servers,with static ips (though i dont think this is an issue)....i can telnet and rlogin from one to the other....if i FTP from on et othe other and try to execute : cd /user return /user : no such file or... (1 Reply)
Discussion started by: BAM
1 Replies

10. UNIX for Advanced & Expert Users

Very Challenging Question! Need help bad!

I am in desperate need of an answer to this question. I have looked everywhere (even the man pages) and found very little. Solaris has the concept of "plumbing" a network interface. What does this mean? I would be really greatful to whoever could help me answer this question. I am so... (1 Reply)
Discussion started by: Sparticus007
1 Replies
Login or Register to Ask a Question