Sponsored Content
Top Forums Shell Programming and Scripting Tricky - Need help on Shell script variables Post 302396824 by shantoshkumar on Friday 19th of February 2010 11:38:32 AM
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...
 

10 More Discussions You Might Find Interesting

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

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

3. Shell Programming and Scripting

Tricky Shell script

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

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

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

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

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

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

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

10. 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
escape(1)							Mail Avenger 0.8.3							 escape(1)

NAME
escape - escape shell special characters in a string SYNOPSIS
escape string DESCRIPTION
escape prepends a "" character to all shell special characters in string, making it safe to compose a shell command with the result. EXAMPLES
The following is a contrived example showing how one can unintentionally end up executing the contents of a string: $ var='; echo gotcha!' $ eval echo hi $var hi gotcha! $ Using escape, one can avoid executing the contents of $var: $ eval echo hi `escape "$var"` hi ; echo gotcha! $ A less contrived example is passing arguments to Mail Avenger bodytest commands containing possibly unsafe environment variables. For example, you might write a hypothetical reject_bcc script to reject mail not explicitly addressed to the recipient: #!/bin/sh formail -x to -x cc -x resent-to -x resent-cc | fgrep "$1" > /dev/null && exit 0 echo "<$1>.. address does not accept blind carbon copies" exit 100 To invoke this script, passing it the recipient address as an argument, you would need to put the following in your Mail Avenger rcpt script: bodytest reject_bcc `escape "$RECIPIENT"` SEE ALSO
avenger(1), The Mail Avenger home page: <http://www.mailavenger.org/>. BUGS
escape is designed for the Bourne shell, which is what Mail Avenger scripts use. escape might or might not work with other shells. AUTHOR
David Mazieres Mail Avenger 0.8.3 2012-04-05 escape(1)
All times are GMT -4. The time now is 07:30 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy