将通话记录备份和恢复 XML callist 转换为 csv

Convert Call Logs Backup & Restore XML callist into csv

我用

从我所有的通话文件中创建了一个大文件 all.xml
echo '<?xml version='1.0' encoding='UTF-8' standalone='yes' ?>
<!--File Created By Call Logs Backup & Restore v3.70 on 23/12/2016 03:02:21-->
<?xml-stylesheet type="text/xsl" href="calls.xsl"?>
<calls count="500">
'>all.xml
for i in calls-*.xml; do head -n-1 "$i"|tail -n+5; done>>all.xml
echo "</calls>">>all.xml

现在我尝试将此格式的 callist 导出到 csv:

<?xml version='1.0' encoding='UTF-8' standalone='yes' ?>
<!--File Created By Call Logs Backup & Restore v3.70 on 23/12/2016 03:02:21-->
<?xml-stylesheet type="text/xsl" href="calls.xsl"?>
<calls>
  <call number="+492345678" duration="0" date="1426694707547" type="3" readable_date="18.03.2015 17:05:07" contact_name="Someone" />
  <call number="+492345679" duration="3" date="1426695646292" type="2" readable_date="18.03.2015 17:20:46" contact_name="Someone else" />
  <call number="+492345670" duration="0" date="1426695687556" type="2" readable_date="18.03.2015 17:21:27" contact_name="Someone" />
</calls>

我试过 xmlstarlet:

xmlstarlet sel -B -t -m "//calls/call" -n -m "*" -v . -o , all.xml |less

但我猜这只会给我一个空列表,因为在每个调用中没有值,但在每个调用元素的选项中。

我无法在 manuals, I found 的帮助下找出答案 如何获取 CSV 文件中的选项?

尝试将 -m "*" 更改为 -m "@*"

将单个 xml 属性转换为 csv 的不同方法:

xmlstarlet sel -t -m "//calls/call" -v "concat(@number,',',@duration,',',@date,',',@type,',',@readable_date,',',@contact_name)" -n file.xml

输出:

+492345678,0,1426694707547,3,18.03.2015 17:05:07,Someone
+492345679,3,1426695646292,2,18.03.2015 17:20:46,Someone else
+492345670,0,1426695687556,2,18.03.2015 17:21:27,Someone