Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Jessica Lares

macrumors G3
Original poster
Oct 31, 2009
9,612
1,056
Near Dallas, Texas, USA
I see, that's a pretty messy file without linebreaks so a grep match in this case grabs much more then it suppose to, which is why the spread sheet gets messed up.

Right. So when I format one of them with Xmplify, it gives me this in the first cell:

2013-01-07T17:45:54+00:00; 30'11"; 0.96 mi; 1174188; 31'30" / mi;

Which is what I'm looking for (and cleaner). So, if I format all of them, that should be pretty much all that's needed.
 

subsonix

macrumors 68040
Feb 2, 2008
3,551
79
Right. So when I format one of them with Xmplify, it gives me this in the first cell:



Which is what I'm looking for (and cleaner). So, if I format all of them, that should be pretty much all that's needed.

If you want to do that, I never used Xmplify . Otherwise you may use an xml library to parse the file in python for example and print the nodes of interest. The pure text processing approach grep/awk/sed etc. has it's problems if the formatting is messy and/or inconsistent.

I tried this in Python. It prints out the nodes of one xml file, and can then be used in a loop to process all files.

Code:
#!/usr/bin/python

import sys
from xml.dom import minidom

# check for arguments
if len(sys.argv) < 2 :
    sys.stderr.write('Missing argument.\n')
    exit(1)

# open and parse the XML file
dom = minidom.parse(sys.argv[1])

# function to print node values
def printNodeValue( name, delimiter ):
    for node in dom.getElementsByTagName( name ):
        sys.stdout.write( node.childNodes[0].nodeValue )
        sys.stdout.write( delimiter )

# print node values
printNodeValue('time', '; ')
printNodeValue('durationString', '; ')
printNodeValue('distanceString', '; ')
printNodeValue('pace', '\n')

Then make the file executable and run it:

Code:
chmod +x parser.py
for i in *.xml ; do ./parser.py "$i" ; done > nike+.csv

Which for the file you had gives this (three copies).

Code:
2013-12-21T19:38:56+00:00; 11'09"; 0.25 mi; 44'41" / mi
2013-12-21T19:38:56+00:00; 11'09"; 0.25 mi; 44'41" / mi
2013-12-21T19:38:56+00:00; 11'09"; 0.25 mi; 44'41" / mi
 
Last edited:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.