Tricky - Need help on Shell script variables


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Tricky - Need help on Shell script variables
# 1  
Old 02-19-2010
Tricky - Need help on Shell script variables

Hi, I have a requirement in which i have to read a csv file and put data in certain set of variables:
File content:
Code:
VP-DTL-REC-CNT, ,854840,0.00,VP-PAID-AMT, ,0,32280885.17,VP-PAT-PAID-AMT, ,0,9930244.32,VP-PAID-REV-CNT, ,484927,0.00,VP-REJ-CNT, ,369913,0.00, , ,0,0.00, , ,0,0.00, , ,0,0.00, , ,0,0.00,CYCL_SRCE_DT, ,01/25/2010 00:00:00,1

This is the code i have written:

Code:
var=`cat ${INFA_BALANCING_DETAILS}`
 for i in 0 1 2 3 4 5 6 7 8 9
  do
   for j in 1 2 3 4
   do
    v=`expr 4 \* $i + $j`
    u=`expr $i + 1`
    case "$j" in
      1 ) ACTN_0${u}_NM=`echo $var|cut -d"," -f"$v"` ; exit ;;
      2 ) ACTN_0${u}_CD=`echo $var|cut -d"," -f"$v"` ;;
      3 ) ACTN_0${u}_CNT=`echo $var|cut -d"," -f"$v"` ;;
      4 ) ACTN_0${u}_AMT=`echo $var|cut -d"," -f"$v"` ;;
      * ) exit ;;
    esac
   done
  echo "$ACTN_0${u}_NM" "$ACTN_0${u}_CD" "$ACTN_0${u}_CNT" "$ACTN_0${u}_AMT"
  done

My problem: The assignment is not working since the LHS of the assignment is also varying.
Error: ACTN_01_NM=VP-DTL-REC-CNT: not found
Its trying to execute this statement.

Can anyone suggest me how to do this using korn shell script, is it possible to use a varying value on LHS of assignment?

Quick help is appreciated.

Last edited by pludi; 02-19-2010 at 12:49 PM.. Reason: code tags, please...
# 2  
Old 02-19-2010
It should definitely be easier if you explain what exactly you're trying to achieve.
Bare in mind that the pure shell is not the most appropriate tool for processing text files.
# 3  
Old 02-19-2010
Instead of:
Code:
      1 ) ACTN_0${u}_NM=`echo $var|cut -d"," -f"$v"` ; exit ;;

try:
Code:
      1 ) eval ACTN_0${u}_NM='`echo $var|cut -d"," -f"$v"`' ; exit ;;

# 4  
Old 02-20-2010
MySQL Thanks

Smilie Thanks alister, it worked fine for me.

radoulov, thanks for your input, i was just looking how i can use the value of one variable as a variable name.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script to create runtime variables based on the number of parameters passed in the script

Hi All, I have a script which intends to create as many variables at runtime, as the number of parameters passed to it. The script needs to save these parameter values in the variables created and print them abc.sh ---------- export Numbr_Parms=$# export a=1 while do export... (3 Replies)
Discussion started by: dev.devil.1983
3 Replies

2. Shell Programming and Scripting

How to write config shell script to pass variables in master shell script?

Dear Unix gurus, We have a config shell script file which has 30 variables which needs to be passed to master unix shell script that invokes oracle database sessions. So those 30 variables need to go through the database sessions (They are inputs) via a shell script. one of the variable name... (1 Reply)
Discussion started by: dba1981
1 Replies

3. UNIX for Dummies Questions & Answers

How to write Config shell script to pass variables in master shell script?

Dear Unix gurus, We have a config shell script file which has 30 variables which needs to be passed to master unix shell script that invokes oracle database sessions. So those 30 variables need to go through the database sessions (They are inputs) via a shell script. one of the variable name... (1 Reply)
Discussion started by: dba1981
1 Replies

4. HP-UX

Shell script variables

hi everyone, i'm writing shell script on hp-ux server that run by root user then (inside the script) su to database user and appl user..the reason for this script is to run some commands involve all users root and database and appl..anyway, variables when root in control is ok but when su, the... (1 Reply)
Discussion started by: neemoze
1 Replies

5. Shell Programming and Scripting

Variables in shell script

mysqldump --compact --add-drop-table -h192.168.150.80 -uroot -p somePass $combined | sed '/$combined/$table/g' | mysql $databaseThe sed part is not working from the above statement. The variables combined and table are already defined and instead of showing the actual variable, it is executing the... (4 Replies)
Discussion started by: shantanuo
4 Replies

6. Shell Programming and Scripting

Accessing variables of one shell script in another shell script

Hi All, I have a shell script called sample1.sh where I have 2 variables. Now I have another shell script called sample2.sh. I want the variables in sample1.sh to be available to sample2.sh. For example. In sample1.sh I am finding the sum of 2 numbers namely a and b. Now I want to access... (2 Replies)
Discussion started by: rsendhilmani
2 Replies

7. Shell Programming and Scripting

Accessing variables of one shell script in another shell script

I have a variable $exe in a shell script file a.sh which I need to access in another shell script file b.sh. How can I do that? :rolleyes: Thanks!! (2 Replies)
Discussion started by: looza
2 Replies

8. Shell Programming and Scripting

Tricky Shell script

The Problem is mentioned below (61 Replies)
Discussion started by: namishtiwari
61 Replies

9. Shell Programming and Scripting

Shell Script Variables

HI guys I need to store the output of a sql query in a variable, can you tell me how to do that eg) select count(*) from s_escl_req $count = count(*) from s_escl_req how would i store the count(*) from the sql statement in a variable called $count. thanks (3 Replies)
Discussion started by: ragha81
3 Replies

10. Shell Programming and Scripting

Tricky script question

Hi, I'm in the midst of writing a UNIX script that sftp's files to an external host and am stuck with a problem. The problem is that the files created on my server as a order number that correlates to a sequence of directories on the remote host which is where the file should be ftp'ed. ... (3 Replies)
Discussion started by: budrito
3 Replies
Login or Register to Ask a Question