Q. I have a XML file which contain below content, I want to get all IP’s in to one array, Passwords in to other array, Usernames in to third array and instanceCount to other array. Can you show me how write a shell script for this?

My XML file content is


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
arrx=($(grep $i temp.xml | sed -r “s/<(|/)$i>//g”))
eval arr${j}='($(echo ${arrx[@]}))’
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.

The following two tabs change content below.
Mr Surendra Anne is from Vijayawada, Andhra Pradesh, India. He is a Linux/Open source supporter who believes in Hard work, A down to earth person, Likes to share knowledge with others, Loves dogs, Likes photography. He works as Devops Engineer with Taggle systems, an IOT automatic water metering company, Sydney . You can contact him at surendra (@) linuxnix dot com.