My XML file content is
<Users>
<Host>
<hostAddress>180.144.226.47</hostAddress>
<userName>pwdfe</userName>
<password>hjitre</password>
<instanceCount>2</instanceCount>
</Host>
<Host>
<hostAddress>180.144.226.87</hostAddress>
<userName>trrrer</userName>
<password>jhjjhhj</password>
<instanceCount>3</instanceCount>
</Host>
<Host>
<hostAddress>180.455.226.87</hostAddress>
<userName>wewqw</userName>
<password>dfsdfd</password>
<instanceCount>3</instanceCount>
</Host>
</Users>
And the file name is temp.xml Here is the script which will read these values in to different arrays.
#!/bin/bash j=1
for i in hostAddress userName password instanceCount
do
arrx=($(grep $i temp.xml | sed -r “s/<(|/)$i>//g”))
eval arr${j}='($(echo ${arrx[@]}))’
((j++))
done
echo “Value of arr1 is ${arr1[@]}”
echo “Value of arr2 is ${arr2[@]}”
echo “Value of arr3 is ${arr3[@]}”
echo “Value of arr4 is ${arr4[@]}”
I used arrays to store the filtered values. Hope this script helps some one.
Latest posts by Surendra Anne (see all)
- Docker: How to copy files to/from docker container - June 30, 2020
- Anisble: ERROR! unexpected parameter type in action:
Fix - June 29, 2020 - FREE: JOIN OUR DEVOPS TELEGRAM GROUPS - August 2, 2019
- Review: Whizlabs Practice Tests for AWS Certified Solutions Architect Professional (CSAP) - August 27, 2018
- How to use ohai/chef-shell to get node attributes - July 19, 2018