shell script to find a word then make new

February 9, 2011 at 00:53:19
Specs: Windows XP
Hi,

i need to create a shell script which will find a string and then make a new string based on below logic


FILE :
sv_s = ""
sv_s = "feesOutst,feesOutstCncyCode| "
sv_s = sv_s + " SELECT SUM(USER_CALC_CHRGE_AMT-CHRGE_AMT_COLLECTED - CHRGE_WAIVED) , CRNCY_CODE"
sv_s = sv_s + " FROM CHAT"
sv_s = sv_s + " WHERE ACID ='"+ CUST.GLDATA.solTransferAcid +"'"

Expected output

1. wherever we find WHERE ACID ='"+ CUST.GLDATA.solTransferAcid +" we need to replace with "?WHERE ACID ='"+?SVAR+"

2. Along with this we need to create a variable say NEW = "CUST.GLDATA.solTransferAcid|SECOND value|THIRD VALUE|and so on... "

3. This variable should create new variable at a specific location jus above sv_s="" (in the above file example)

4. there will be multiple locations where sv_s="" so i need to define a fixed range of lines in which to search and create new variable and make replacement

Request help on writing logic for this.thanks..


See More: shell script to find a word then make new

Report •

#1
February 9, 2011 at 00:54:50
more details about point 4


4. there will be multiple locations where sv_s="" so i need to define a fixed range of lines in which to search and create new variable and make replacement, i can use sv_d = select(sv_s) as the last line till which these changes need to be done


Report •

#2
February 9, 2011 at 07:28:43
In this forum, we have discussed using gres: the Global Regular Expression Substitution:

http://www.computing.net/answers/un...

After trying it, if you have any questions, let me know.


Report •

#3
February 9, 2011 at 23:46:44
my real doubt is regarding forming of new variable with many different variables. for e.g a, b, c can be anywhere and multiple locations in the file. initially i need to make X = a|b|c then replace each occurence of a, b ,c with new value.

also, X should be placed at the right location otherwise the script execution will fail.

Kindly advice

below is a actual example from my fle which needs the changes.

sv_s = ""
sv_s = "feesOutst,feesOutstCncyCode| "
sv_s = sv_s + " SELECT SUM(USER_CALC_CHRGE_AMT-CHRGE_AMT_COLLECTED - CHRGE_WAIVED) , CRNCY_CODE"
sv_s = sv_s + " FROM CHAT"
sv_s = sv_s + " WHERE ACID = a"
sv_s = sv_s + " AND RECOVERABLE_FLG = 'Y'"
sv_s = sv_s + " AND BANK_ID = b"
sv_s = sv_s + " GROUP BY CRNCY_CODE"
sv_c = urhk_dbCursorOpen(sv_s)

##############
#Some processing logic
###############

sv_s = ""
sv_s = "feeRateCode|"
sv_s = sv_s + " SELECT CHRG_RATE_CODE"
sv_s = sv_s + " FROM GCT"
sv_s = sv_s + " WHERE BANK_ID = a"
sv_d = urhk_dbSelect(sv_s)

New File: should be like

X = “a|b”
sv_s = ""
sv_s = "feesOutst,feesOutstCncyCode| "
sv_s = sv_s + " SELECT SUM(USER_CALC_CHRGE_AMT-CHRGE_AMT_COLLECTED - CHRGE_WAIVED) , CRNCY_CODE"
sv_s = sv_s + " FROM CHAT"
sv_s = sv_s + " WHERE ACID = ?X"
sv_s = sv_s + " AND RECOVERABLE_FLG = 'Y'"
sv_s = sv_s + " AND BANK_ID = ?X"
sv_s = sv_s + " GROUP BY CRNCY_CODE"
sv_c = urhk_dbCursorOpen(sv_s)

##############
#Some processing logic
###############
X = “a”

sv_s = ""
sv_s = "feeRateCode|"
sv_s = sv_s + " SELECT CHRG_RATE_CODE"
sv_s = sv_s + " FROM GCT"
sv_s = sv_s + " WHERE BANK_ID = ?X"
sv_d = urhk_dbSelect(sv_s)


Report •

Related Solutions

#4
February 10, 2011 at 09:23:01
The syntax you are using for concatenating strings is not correct. The plus sign is illegal.

Here is an example in the korn shell. Also, note that you should not have spaces around the = sign:

#!/bin/ksh

sv_s="feesOutst,feesOutstCncyCode| "
echo "$sv_s"

sv_s=${sv_s}" SELECT SUM(USER_CALC_CHRGE_AMT-CHRGE_AMT_COLLECTED - CHRGE_WAIVED) , C
RNCY_CODE"

echo "$sv_s"


Report •

#5
February 10, 2011 at 19:07:45
sorry i did not mention this before..

The above file is not to be run in unix. i need to make a shell script which will take this file as input and do the needful.


Report •

Ask Question