what I have to do is : have to check the data in between tags which are in bold is valid or not ... means have to check whether its a email address or not ... to check this i need to view the data in between those tags.
and have to find the length of the data which is in between tag...means length of FDF@gmail.COM
for this I need to get the data from the xml file whereever <EmailAddress></EmailAddress> tag is present.
sorry if its already asked...i checked but i didnt get Exatly matching result for my requirement
No surprise, you are using ksh. This solution only works in bash or zsh.
With ksh i can't help you. But this should be easy. Just google for arrays
in ksh. $(...) execute the following command in a subshell. (...) puts
the things inside into an array. Perhaps you can replace (...) by
`...` (backticks). But i don't know.
Probably you will have to adjust the regexp, too. By now it will not
match emails with dots, underscores,dashes etc.
I got the answer but works with 1st occurance of the tag only
awk -F '</?EmailAddress>' '{print $2}' 456.xml
but i need for multiple times .... means email address tag exists for multiple times in the file ...
so need to check whole xml file for email address and get them wherever <EmailAddress></EmailAddress> tag is present.
Hope all is fine. I am using Bourne Shell (sh) . I have this simple XML structure ( it's very well defined and this is how this fixed structure will be). The exact sample is as follows (There will always be one value per tag):
Now I want to create an array with only the values of the xml tags . For e.g. H_ARRAY ('180.144.226.47','180.144.226.87','180.144.226.87'). Then I will traverse throught the values of array accordingly. I am newbie to shell scripting and especially "SED" command which after repeated attempts was unable to understand. Would appreciate your help. Let me know if I missed on something,
It will write the results of the sed command into an array HOSTS.
echo ${HOSTS[1]} etc.
Will give you the values.
Sed is best learned by example. There are many pages with sed one liners.
This one here does the following:
-n only print if asked to print a line
's/ substitute
^<host every line starting with host
\([^<]\) every character except a "<" and save what you have found in "\1"
. the rest of the line
/\1/ substitute by what we have just save in \1
p' print this line.
The command does two tasks at a time: a) it finds all lines starting with
host..., b) it extracts the value between the tags.