我正在处理一个 OFX(银行交易)文件。我的银行不使用<NAME>
标签来指定收款人,但此信息是<MEMO>
标签的子字符串。
所以,我的文件是这样的:
...ofx headers and other stuff
...line below is a transaction
<STMTTRN>
<TRNTYPE>OTHER</TRNTYPE>
<DTPOSTED>20160609120000</DTPOSTED>
<TRNAMT>-4.00</TRNAMT>
<FITID>2016060914000</FITID>
<CHECKNUM>000000700132</CHECKNUM>
<REFNUM>700.132</REFNUM>
<MEMO>Credit Card Payment - 09/06 18:37 Walmart 2th street</MEMO>
</STMTTRN>
...continues other transactions and end of file
我想匹配每个<MEMO>
标签,提取收款人姓名(Walmart 2th street
在本例中)并用<NAME>
. 我的输出将是:
...ofx headers and other stuff
...line below is a transaction
<STMTTRN>
<TRNTYPE>OTHER</TRNTYPE>
<DTPOSTED>20160609120000</DTPOSTED>
<TRNAMT>-4.00</TRNAMT>
<FITID>2016060914000</FITID>
<CHECKNUM>000000700132</CHECKNUM>
<REFNUM>700.132</REFNUM>
<MEMO>Credit Card Payment - 09/06 18:37 Walmart 2th street</MEMO>
<NAME>Walmart 2th street</NAME>
</STMTTRN>
...continues other transactions and end of file
另一个工具如 awk 可能是一个解决方案。