我有这样的表:
"Date","Time","Open","High","Low","Close","Volume"
06/28/2004,0931,37.49,37.50,37.45,37.46,1049200
06/28/2004,0932,37.48,37.50,37.45,37.48,450700
06/28/2004,0933,37.48,37.50,37.46,37.49,493700
06/28/2004,0934,37.49,37.50,37.47,37.47,756100
06/28/2004,0935,37.48,37.49,37.46,37.48,309000
不幸的是,时间列只是数字,并且:
在数字对之间缺失。我怎样才能纠正这个问题,以便表中的时间正确显示,如下所示:
"Date","Time","Open","High","Low","Close","Volume"
06/28/2004,09:31,37.49,37.50,37.45,37.46,1049200
06/28/2004,09:32,37.48,37.50,37.45,37.48,450700
06/28/2004,09:33,37.48,37.50,37.46,37.49,493700
06/28/2004,09:34,37.49,37.50,37.47,37.47,756100
06/28/2004,09:35,37.48,37.49,37.46,37.48,309000
答案1
awk -vFS="" -vOFS="" 'NR>1 {$13=$13":"}1' file
"Date","Time","Open","High","Low","Close","Volume"
06/28/2004,09:31,37.49,37.50,37.45,37.46,1049200
06/28/2004,09:32,37.48,37.50,37.45,37.48,450700
06/28/2004,09:33,37.48,37.50,37.46,37.49,493700
06/28/2004,09:34,37.49,37.50,37.47,37.47,756100
06/28/2004,09:35,37.48,37.49,37.46,37.48,309000
-vFS="" -vOFS=""
将输入和输出字段分隔符设置为非。
NR>1
以避免第一行发生更改,这意味着更改将从第 2 行开始应用
{$13=$13":"}
将在字符串 13 之后插入冒号