Insert value of env variable in xml file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Insert value of env variable in xml file
# 1  
Old 10-15-2012
Insert value of env variable in xml file

Hello,
I have the following variables set in my env

Code:
echo $MY_XSD_FILE
/home/jak/sample.xsd
echo $MY_INTERVAL_VALUE
4

I want to insert them between the xml tags in my xml file

Code:
cat sample.xml
:::::::::::::::
:::::::::::::::
<property name="FILE"></property>
:::::::::::::::::::::::
::::::::::::::::::::::
<property name="Interval"></property>

So, the output should be

Code:
cat sample.xml
:::::::::::::::
:::::::::::::::
<property name="FILE">/home/jak/sample.xsd</property>
:::::::::::::::::::::::
::::::::::::::::::::::
<property name="Interval">4</property>

Thanks for your time - Jak
# 2  
Old 10-15-2012
Try

Code:
awk -v file="$MY_XSD_FILE" -v Intrl="$MY_INTERVAL_VALUE" '/FILE"><\/property>/{sub("><",">"file"<",$0)}
/Interval"><\/property>/{sub("><",">"Intrl"<",$0)}1' sample.xml > temp_file

mv temp_file sample.xml

# 3  
Old 10-15-2012
Thanks pamu - i will try it and let you know.

jak
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to insert subnode in xml file using xmlstarlet or any other bash command?

I have multiple xml files where i want to update a subnode if the subnode project points to different project or insert a subnode if it doesn't exist using a xmlstarlet or any other command that can be used in a bash script. I have been able to update the subnode project if it doesn't point to... (1 Reply)
Discussion started by: Sekhar419
1 Replies

2. UNIX for Beginners Questions & Answers

Bash: Insert in a variable a file

hi all i have a problem in the bash shell. i'd like insert in a variable a file for example : i have a file datafine.log in this file there is : 17/JUN/2019 i want to insert the value of datafine.log in a variable. Regards Frncesco edit by bakunin: please use CODE-tags for your data... (2 Replies)
Discussion started by: Francesco_IT
2 Replies

3. Shell Programming and Scripting

Insert text after match in XML file

Having a little trouble getting this to work just right. I have xml files that i want to split some data. I have 2 <name> tags within the file I would like to take only the first tag and split the data. tag example. From this. TAB<Name>smith, john</Name> to TAB<Name>smith,... (8 Replies)
Discussion started by: whegra
8 Replies

4. Shell Programming and Scripting

Insert a new subnode in a xml file

Hi, i have an xml file and i want to edit a new sub node in a file like val="<activity android:label="@string/app_name" android_name=".MainActivity1" android:launchMode="singleTask" android:screenOrientation="portrait" ... (1 Reply)
Discussion started by: gautamshrm3
1 Replies

5. Web Development

Deny from env=env-variable Does not work

(Above from Apache docs). On my system, using: SetEnvIf User-Agent Mozilla IsBad=1 Order allow,deny Allow from all Deny from env=IsBad ...I see that environment variable is set (using phpinfo()) but the page is still served. No errors in the Apache logs. (1 Reply)
Discussion started by: gnurob
1 Replies

6. Shell Programming and Scripting

[solved] how to get specific env variable values into a file

greetings! how do i get an env variable that looks like this when echoed: into a file that looks like this: keeping in mind that the two constants are the fields from the env variable will always be in odd positions of the string that need to go into the file AND they will always start... (3 Replies)
Discussion started by: crimso
3 Replies

7. Shell Programming and Scripting

Add env variable in a file

Hi, I have a small requirement set -x `grep IMPACT_HOME=/opt/impact /opt/NETCOOLINST/r.txt | cut -d'=' -f2` if ; then sed 's#IMPACT_HOME=*#d' /opt/NETCOOLINST/r.txt echo "IMPACT_HOME=" >> /opt/NETCOOLINST/r.txt sed 's#IMPACT_HOME=*#IMPACT_HOME=/opt/impact#g' /opt/NETCOOLINST/r.txt... (2 Replies)
Discussion started by: dbashyam
2 Replies

8. Shell Programming and Scripting

insert line into file using variable

Hi all, I am trying to insert couple of lines before first occurance of line3 which occuring after line 5. So I identified the line 5 line number in the file. Also redirected the all line3 line number to out.txt. Now I have problem in inserting the line using the variable $rep. Please help me... (2 Replies)
Discussion started by: aimmanuel
2 Replies

9. Shell Programming and Scripting

insert a variable in the last column of a file

i want to insert a variable in the last column of a file, the columns are separated by "|". I want to insert the variable in everyline of the file . (7 Replies)
Discussion started by: dineshr85
7 Replies

10. Shell Programming and Scripting

script to run shell command and insert results to existing xml file

Hi. Thanks for any help with this. I'm not new to programming but I am new to shell programming. I need a script that will 1. execute 'df -k' and return the volume names with specific text 2. surround each line of the above results in opening and closing xml tags 3. insert the results of step... (5 Replies)
Discussion started by: littlejon
5 Replies
Login or Register to Ask a Question