Question : Question on how to read an XML file using re in bash.

Hello group,

I'm in the middle of a development but an unexpected request has come and I have to read some elements in an XML file. How can I do this using Bash (using regular expression)? I know bash just as user only not as an expert.

This source file I need to read is a huge xml file.

http://wurfl.sourceforge.net/wurfl.xml

I think using bash (regular expression) this would easier to read some elements and export the data into a CSV file. I will appreciate it if you could give me the syntax that I could use to extract some data off the xml file.

Regards.


Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
This is a block of the xml file:
 
I need to extract "user_agent which here has a value as "AUDIOVOX-CDM8912SP" and also its "model name" which is "CDM-8912". 
 
 














































Open in New Window Select All

Answer : Question on how to read an XML file using re in bash.

Depends on what you want to extract and how well formed the XML is.  Regular expressions just don't cope very well with the structure of XML/HTML, so that's why XML/HTML parsers were written.

However, if you just want to exact text from a simple XML tag and the structure is consistent, then you could probably get away with a regex.  

You really need to show an example of what you want to process/extract.
Random Solutions  
 
programming4us programming4us