XML 读取列并根据日期格式添加新数据

XML 读取列并根据日期格式添加新数据

我在 XML 文档中有以下数据

NAME    19/02/2019  23/02/2019  23/02/2019 13:21    12.99   0   12.99   Paid    PayPal
NAME    19/02/2019  23/02/2019  23/02/2019 13:22    12.99   0   12.99   Paid    PayPal
NAME    22/02/2019  23/02/2019  23/02/2019 13:23    12.99   0   12.99   Paid    PayPal
NAME    23/02/2019  23/02/2019  23/02/2019 13:24    12.99   0   12.99   Paid    PayPal
NAME    23/02/2019  23/02/2019  23/02/2019 13:25    12.99   0   12.99   Paid    PayPal
NAME    23/02/2019  23/02/2019  23/02/2019 13:26    12.99   0   12.99   Paid    PayPal

这些列是

   Client Name  Creation Date   Due Date    Date Paid   Subtotal    Credit  Total   Status  Payment Method

我需要将此数据转换为以下内容。在开始处添加的新列将是生成发票的日期,后跟基于它们在我的文档中的顺序的当天的数字顺序,而不是时间,例如 13:21。每天应该从 1 点开始。

19-02-2019-1    NAME    19/02/2019  23/02/2019  23/02/2019 13:21    12.99   0   12.99   Paid    PayPal
19-02-2019-2    NAME    19/02/2019  23/02/2019  23/02/2019 13:22    12.99   0   12.99   Paid    PayPal
22-02-2019-1    NAME    22/02/2019  23/02/2019  23/02/2019 13:23    12.99   0   12.99   Paid    PayPal
23-02-2019-1    NAME    23/02/2019  23/02/2019  23/02/2019 13:24    12.99   0   12.99   Paid    PayPal
23-02-2019-2    NAME    23/02/2019  23/02/2019  23/02/2019 13:25    12.99   0   12.99   Paid    PayPal
23-02-2019-3    NAME    23/02/2019  23/02/2019  23/02/2019 13:26    12.99   0   12.99   Paid    PayPal

我怎样才能做到这一点?最好使用 perl,但任何东西都可以。

答案1

如果您只想修改xml/的文本输出xpath,则将其通过管道传输,awk如 ....

sort -k2 file1 | awk '{head[$2]++;print $2"-"head[$2], $0}'

输出

19/02/2019-1 NAME    19/02/2019  23/02/2019  23/02/2019 13:21    12.99   0   12.99   Paid    PayPal
19/02/2019-2 NAME    19/02/2019  23/02/2019  23/02/2019 13:22    12.99   0   12.99   Paid    PayPal
22/02/2019-1 NAME    22/02/2019  23/02/2019  23/02/2019 13:23    12.99   0   12.99   Paid    PayPal
23/02/2019-1 NAME    23/02/2019  23/02/2019  23/02/2019 13:24    12.99   0   12.99   Paid    PayPal
23/02/2019-2 NAME    23/02/2019  23/02/2019  23/02/2019 13:25    12.99   0   12.99   Paid    PayPal
23/02/2019-3 NAME    23/02/2019  23/02/2019  23/02/2019 13:26    12.99   0   12.99   Paid    PayPal

如果你的输出已经排序,那么就cat file1不用sorting。

相关内容