xml parsing using sed?
Hey guys,
I have a huge xml file like this... Code:
<manufacturers> Code:
grep mfr_id | sed -rn 's@</?mfr_id>@@gp' Today, I am looking to extract <mfr_id> and <name> from <manufacturer_data> Issues I am having. - sed is extracting all instances of <name> So I need to - tell sed to "hold" data between <manufactuer_data> tags and do pattern search to strip <mfr_id> and <name> tags and print them into columns. This is a little above league. Can some one help me out? |
Quote:
I'm sure this can be done w/ sed, but I'd use awk for this one: Code:
awk '/<manufacturers>/,/<\/manufacturers>/{if($0~/<name>/){print gensub(/.*>([^<]+)<.*/,"\\1","1")}}' hooga.xml Cheers, Tink |
The sed looks kinda the same:
Code:
sed -rn '/<manufacturers>/,/<\/manufacturers>/s@</?name>@@pg' file |
Thanks guys, both commands worked. I thought I replied to this thread but now when I was cross checking the thread I realized my response never got posted. I deeply apologize. I used awk example in this case.
|
All times are GMT -5. The time now is 04:15 PM. |