我想通过以下方式通过awk转换文件:
tid|uid|pid|date|type|price|quantity
12345678900000tid1|123uid1|12pid1|2019-01-01|order|1.97|10
收件人:
time|userID|transactioID|group|itemID|transactionType|basket|order|itemsAction|categoryPath|price|channelID
2019-01-01 00:00:01|uid1|tid1|0|pid1|1|0|10|||19.7|null
这是在Ubuntu 16.04上。 gawk已安装。
cat /path/to/file/some_transactions.csv | sed '1d' | awk -F"|" 'BEGIN {print "time|userID|transactionID|group|itemID|transactionType|basket|order|itemsAction|categoryPath|price|channelID"; OFS = "|"}
NR==FNR {print $4" 00:00:01", $2, $1, "0", $3, "1", "0", $7, "", "", $6*$7, "null"}'
实际结果是:
time|userID|transactID|group|itemID|transType|basket|order|itemsAction|categoryPath|price|channelID
|||19.7|null0:00:01|123uid1|12345678900000tid1|0|12pid1|1|0|10
------------
This is the last part and it over writes the first characters.
我该如何解决? 这是某种最大线长吗?