0

I'm trying to extract XML entities with a given time attribute in a large file:

<afs>
<af timestamp="Jun 30 09:11:58 2015">
...
</af>
<af timestamp="Jun 30 09:13:20 2015">
....
</af>
</afs>

I get all the blocks with this script in bash/sed but I can't find any good approach to do it with Python.

m1=`date '+%b %d %H:%M' -d "-1min"`
m2=`date '+%b %d %H:%M' -d "-2min"`
sed -n "/^<af .*\($m1\|$m2)/,/^<\/af>/p" $LOG 

I can't use ElementTree due to an OS limitation to Python 2.4.3 Thanks in advance.

Lechuk
  • 61
  • 4
  • 1
    Read http://stackoverflow.com/a/1732454/3001761. Why not use an actual XML parser? – jonrsharpe Jun 30 '15 at 08:56
  • 1
    Read this thread http://stackoverflow.com/questions/30703593/python-xml-to-csv – Manish Gupta Jun 30 '15 at 08:57
  • @jonrsharpe: The file it's very large, It's not possible to parse with minidom and I can't find any good solution with SAX. I forgot to say that i Can only use python 2.4 due to OS limitation. – Lechuk Jun 30 '15 at 09:13

0 Answers0