Gentoo Archives: gentoo-user

From: Willie Wong <wwong@××××××××××××××.edu>
To: gentoo-user@l.g.o
Subject: Re: [gentoo-user] [OT] rrd to CSV
Date: Sun, 12 Jul 2009 23:56:13
Message-Id: 20090712235959.GB18653@princeton.edu
In Reply to: Re: [gentoo-user] [OT] rrd to CSV by Mick
1 On Sat, Jul 11, 2009 at 03:57:26PM +0100, Penguin Lover Mick squawked:
2 > > > Hmm, I don't think it gets anywhere:
3 > > > =======================================
4 > > > cat test.xml | grep -v NaN | grep '<row>' | tr e ' ' | awk
5 > > > {'print "Q"$2"qcq"$3"qcq"$9"Q"'} | tr Q '"' | tr c ',' | tr q '"'" >
6 > > > test.csv
7 > > >
8 > > > =======================================
9 > > >
10 > > > It just sits there at the > cursor. I think it needs something more to
11 > > > it, or
12 > >
13 > > Looks like a syntax error with improperly nested quotations marks.
14 > >
15 > > The last command in the sequence, which reads
16 > >
17 > > tr q '"'"
18 > >
19 > > try replacing that with
20 > >
21 > > tr q '"'
22 > >
23 > > (remove the final double quote)
24 > >
25 > > W
26 >
27 > Thank you both! It works to a point. This is what the xml file contains:
28 >
29 > <database>
30 > <!-- 2009-07-02 07:41:00 EDT / 1246534860 --> <row><v>
31 > 7.3395000000e+01 </v><v> 4.7990000000e+01 </v></row>
32 >
33 > The CSV file only shows the first value and then it does not pick up the fact
34 > that it is exponential:
35 >
36 > "2009-07-02","07:41:00","7.3395000000"
37 >
38 > How could it be tweaked to a)account for e+01, b)include additional value
39 > fields?
40 >
41
42 Try:
43
44 cat test.xml | grep -v NaN | grep '<row>' | awk {'print "Q"$2"qcq"$3"qcq"$9"qcq"$11"Q"'} | tr Q '"' | tr c ',' | tr q '"'" > test.csv
45
46 Just to help you help yourself later: the 'tr' command "translates".
47 So the command
48
49 tr e ' '
50
51 swaps occurences of the letter e with a blank space. Removing that
52 command keeps the e in the numbers. (Though I am not certain how CSV
53 files deal with e notations...). awk prints the space-separated
54 fields. $2, $3, etc are the number of the field respectively. So
55 adding $11 allows printing the one additional field.
56
57 This, of course, only works if you have the same number of records in
58 each row.
59
60 HTH,
61
62 W
63 --
64 A gossip is someone with a great sense of rumour.
65 Sortir en Pantoufles: up 947 days, 22:39