Unix sed expression to find xml value -


i have xml file on aix system has following tag...

  <g:google_product_category> health &amp; beauty &gt; personal care &gt; cosmetics     </g:google_product_category> 

i trying use sed value of element. far can work out expression print stag tag , end tag...

sed -n '/google_product_category/{s/.*<google_product_category>//         s/<\/google_product_category.*//;p;}' gpf_20150708063022.xml  

can please me this?

original data

the original sample data was:

<g:google_product_category>       text on next line </g:google_product_category> 

for data, sed command works:

sed -n '/^<g:google_product_category>/,/^<\/g:google_product_category>/{         /google_product_category/d; p; }' 

don't print default. between lines matching start , end tags (where tags not indented), if line matches google_product_category, delete it; else print it.

revised data

since question has been revised , new sample data is:

  <g:google_product_category> health &amp; beauty &gt; personal care &gt; cosmetics     </g:google_product_category> 

with leading blanks on tag lines (and horribly sloppy layout boot), carets ^ anchor match start of line not appropriate. revised script, therefore, is:

sed -n '/<g:google_product_category>/,/<\/g:google_product_category>/{         /google_product_category/d; p; }' 

don't print default. between lines containing start , end tags (where tags may indented, , may preceded or followed arbitrary material ignored), if line matches google_product_category, delete it; else print it.

given composite , extended data file this:

<g:google_product_category>       text on next line </g:google_product_category>       <g:google_product_category>     health &amp; beauty &gt; personal care &gt; cosmetics         </g:google_product_category>      <g:google_category>         garbage, trash, , delectable goodies.     </g:google_category> 

the output revised script is:

      text on next line     health &amp; beauty &gt; personal care &gt; cosmetics 

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -