linux - AWK 日期到纪元

标签 linux bash unix awk

我有以下从文件返回日期的命令

tail -1 MyFile | awk -F ',' '{print $7}'

像这样返回日期 04/16/12 20:44:19

我想通过将 $7 输入 date -d $7 +%s

以某种方式修改 awk 命令,从而将该日期转换为纪元时间

最佳答案

我认为 awk 对于这项工作来说有点重,cut 可能稍微轻一点:

tail -1 MyFile | date -d "`cut -d, -f7`" +%s

当然你也可以用 awk 来完成:

tail -1 MyFile | date -d "`awk -F, '{ print $7 }'`" +%s

关于linux - AWK 日期到纪元,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10180609/

相关文章:

linux - 并行下载 url 列表并重命名

git - 在 bash 脚本中检测当前目录

bash - 推送到heroku git master时忽略警告

python - 如何对文件使用 select() 函数

linux - 为什么open函数在linux下没有O_SEARCH标志?

c - 访问 xtime 变量 Linux 内核

linux - 使用 awk/sed 重新格式化长文件

python - 使用 python 运行 bash 脚本 - TypeError : bufsize must be an integer

c - 如何解决C中的SIGSEGV、段错误?

linux - 如何在shell中同时定义和打印变量值