Sponsored Content
Full Discussion: String substitution
Top Forums Shell Programming and Scripting String substitution Post 302246464 by ctrl-alt-del on Monday 13th of October 2008 05:29:31 PM
Old 10-13-2008
String substitution

Hi,

I have a properties file (myprop.properties) which contains some values:
@oneValue@==tcp://localhost:1234
@twoValue@==tcp://localhost:4563
@threeValue@==tcp://localhost7895

I have a xml file (myXmlFile.xml)which contains some tokens:
<application name="aTest">
<NameValuePair>
<name>firstName</name>
<value>@oneValue@</value>
</NameValuePair>
<NameValuePair>
<name>secondName</name>
<value>@twoValue@</value>
</NameValuePair>
</application>


I want to replace the tokens in the file myXmlFile.xml by the values of the myprop.properties. I did a script but I cannot manage to match the tokens with awk, I always get the string "nothing" any ideas?



#!/bin/ksh

exec 0< myXmlFile.xml

while read line
do
count=0

for token_per_line in $(cat myprop.properties)
do

first_char=`echo ${token_per_line} | cut -c1`

if [ "$first_char" != "#" ] && [ $count -lt 1 ]; then

token_variables=`echo "$token_per_line" | grep -v '#'| awk -F'==' '{print $1}'`
token_values=`echo "$token_per_line" | awk -F'==' '{print $2}'`

echo $line | awk -v token_var="$token_variables" token_val="$token_values" '{

{

if ($0 ~ /token_var/) {
print "matching"
gsub($token_variables, $token_values, $line);
print $0
}
else {
print "nothing"
}
}

}'
count=$count+1
fi
done
done
exec 0<&3



Regards
John
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Sed String Substitution

Hi! I've the following script code with an input parameter: sed 's/oldstring/$1/g' myfile > newfile (I launch it with comman line: $ MyShell newstring) Problem: the substituion doesn't work (oldstring becomes $1, instead of newstring). How could I solve this situation? Thanks, ... (2 Replies)
Discussion started by: pciatto
2 Replies

2. Shell Programming and Scripting

String Substitution Question

When I run the script I pass in 2 expressions (ex. replace.ksh new old) I want the script to go line by line for a given file in a given directory and replace the word new with old. Of course in my line where I have the awk statement it is replacing the 2nd word with 1st instead of new with... (3 Replies)
Discussion started by: goodrics
3 Replies

3. Shell Programming and Scripting

Sed - substitution for whole string

Hello I have several files where a string similar to this appears: /home/workload/bin/ProcDly/scrpts/T54.sh > $LOG I need to change it to something like this: $VARIABLE > $LOG However, due to the configuration of the rest of the files, I should only find this string by the... (4 Replies)
Discussion started by: Scarlos
4 Replies

4. UNIX for Advanced & Expert Users

String Substitution

Hey ppl, Could u tell me how to replace such a string xyz->x with XYZ(x), where x can be any variable accessible by pointer to structure, xyz in an entire file? (1 Reply)
Discussion started by: laxmi
1 Replies

5. Shell Programming and Scripting

string substitution

Hey ppl, Could u tell me how to replace such a string xyz->x with XYZ(x), where x can be any variable accessible by pointer to structure, xyz in an entire file? (3 Replies)
Discussion started by: laxmi
3 Replies

6. Shell Programming and Scripting

substitution of string in brackets

Hi friends! I have a tab delimited file with two columns : GB_45_DRB SP:0139466(mrmi sisignm)|SP:3674(fllflg_itoioh)|SP:68954779(RMTKLGF to emmdm-roomto) GB_45_DRD SP:475928(mgmdksi rikgkg)|SP:587959(roykgl tiic-tm)|SP:0139466(mrmi sisignm)|SP:3674(fllflg_itoioh)|SP:68954779(RMTKLGF to... (4 Replies)
Discussion started by: jacks
4 Replies

7. Shell Programming and Scripting

a specific string substitution

hi guys...need some help here... i am making a a script to automatically install netbackup client...so its gonna write a configuration file according to the host name.... the line would be something like this CLIENT_NAME = odel_bkp.test.com the thing is ...the host name in reallity is... (2 Replies)
Discussion started by: razael
2 Replies

8. Shell Programming and Scripting

string substitution in perl

Hi, I have a template file and want to replace 3 parameters to the values that I want. these values are in a parameter file. Any idea how to do this in perl? the parameter file looks like: host_name = jupiter PORT = 1562 IPADDRESS = 10.1.34.10 the template file has lots of entry.... (1 Reply)
Discussion started by: melanie_pfefer
1 Replies

9. Shell Programming and Scripting

Substitution within string command

I have the following code: strfuture=abcdefghi ver=${strfuture:${count}:1} mj7777_ver=${ver} start_mj7777_iteration let count=count+1 When it is executed I get bad substitution. The same if I use ver=${strfuture:$count:1} mj7777_ver=${ver}... (6 Replies)
Discussion started by: Bruble
6 Replies

10. Programming

COBOL: Substitution in string

We have a formatted screen system where a driver program passes the locations of a list of files that called programs may be using. It will look something like this: /{number of characters varies}/DATA/MASTERFILEBecause of the size of some files we will be splitting older records into a history... (2 Replies)
Discussion started by: wbport
2 Replies
asadmin-list-resource-adapter-configs(1AS)			   User Commands			asadmin-list-resource-adapter-configs(1AS)

NAME
asadmin-list-resource-adapter-configs, list-resource-adapter-configs - lists the configuration information created in domain.xml for the connector module SYNOPSIS
list-resource-adapter-configs --user admin_user [--password admin_password][--host localhost] [--port 4848][--secure|-s] [--passwordfile filename] [--terse=false] [--echo=false] [--interactive=true] [--verbose=false][--ranameconnector_module_name] Lists the configuration information in the domain.xml for the connector module. It lists an entry called resource-adapter-config in the domain.xml. This command is supported in remote mode only. OPTIONS
--user authorized domain application server administrative username. --password password to administer the domain application server. --host machine name where the domain application server is running. --port port number of the domain application server listening for administration requests. --secure if true, uses SSL/TLS to communicate with the domain application server. --passwordfile file containing the domain application server password. --terse indicates that any output data must be very concise, typically avoiding human-friendly sentences and favoring well- formatted data for consumption by a script. Default is false. --echo setting to true will echo the command line statement on the standard output. Default is false. --interactive if set to true (default), only the required password options are prompted. --verbose if set to true the properties that are configured are also listed. Default is false. OPERANDS
raname the value kept in the resource-adapter-name in the domain.xml file. Example 1: Using list-resource-adapter-configs asadmin> list-resource-adapter-configs --username admin1 --password adminadmin1 Command list-resource-adapter-configs executed successfully EXIT STATUS
0 command executed successfully 1 error in executing the command asadmin-create-resource-adapter-config(1AS), asadmin-delete-resource-adapter-config(1AS) J2EE 1.4 SDK March 2004 asadmin-list-resource-adapter-configs(1AS)
All times are GMT -4. The time now is 05:32 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy