【发布时间】:2018-03-28 15:58:09
【问题描述】:
这是输入的 .csv 文件
"item1","10/11/2017 2:10pm",1,2, ...
"item2","10/12/2017 3:10pm",3,4, ...
.
.
.
现在,我想将第二列(日期)转换为这种特定格式
date -d '10/12/2017 2:10pm' +'%Y/%m/%d %H:%M:%S',以便 "10/12/2017 2:10pm" 转换为 "2017/10/12 14:10:00"
期待输出文件
"item1","2017/10/11 14:10:00",1,2, ...
"item2","2017/10/12 15:10:00",3,4, ...
.
.
.
我知道可以使用 bash 或 python 来完成,但我想在 单行命令 中完成。有任何想法吗?有没有办法将date 结果传递给sed?
【问题讨论】:
-
@MarcLambrichs,OP 没有提到
awk,那么为什么要添加那个标签呢? -
因为 OP 声明 我想在单行命令中完成。有什么想法吗?。这就是为什么。
-
@MarcLambrichs, “Did You Lose the Keys Here?” “No, But the Light Is Much Better".
-
@agc awk 是解决此类问题的有效工具。添加标签吸引了更多的答案,这有利于OP。
-
@MarcLambrichs 我更喜欢你的回答,但我现在找不到。
标签: shell datetime awk sed command-line