将呼叫日志备份和还原XML callist转换为csv

将呼叫日志备份和还原XML callist转换为csv,xml,bash,csv,xmlstarlet,Xml,Bash,Csv,Xmlstarlet,我用所有调用文件创建了一个大文件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

我用所有调用文件创建了一个大文件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
但我想这只会给我一个空列表,因为每个调用中没有值,而是每个调用元素的选项中都有值

我无法在医生的帮助下找到答案
如何在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
*任意选择元素@*选择任何属性。看看酷,我还在concat中添加了带“\”的引号
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