【发布时间】:2021-09-11 05:28:09
【问题描述】:
$cat syslog* | grep -a "CRON" | grep "CMD"
Jun 24 22:17:01 ubuntu1804-template CRON[7772]: (root) CMD ( cd / && run-parts --report /etc/cron.hourly)
Jun 24 23:17:01 ubuntu1804-template CRON[7779]: (root) CMD ( cd / && run-parts --report /etc/cron.hourly)
2021-06-24T10:05:01.590200-07:00 ubuntu1804-template CRON[7772]: (root) CMD ( cd / && run-parts --report /etc/cron.hourly)
2021-06-25T10:05:01.590200-07:00 ubuntu1804-template CRON[7772]: (root) CMD ( cd / && run-parts --report /etc/cron.hourly)
我想将其转换为具有三列的 csv 文件。正在从 variable 获取 Hostname 列
预期输出:
Date Hostname Message
Jun 24 22:17:01 $variable CMD ( cd / && run-parts --report /etc/cron.hourly)
Jun 24 23:17:01 $variable CMD ( cd / && run-parts --report /etc/cron.hourly)
2021-06-24T10:05:01.590200-07:00 $variable CMD ( cd / && run-parts --report /etc/cron.hourly)
2021-06-25T10:05:01.590200-07:00 $variable CMD ( cd / && run-parts --report /etc/cron.hourly)
我正在尝试使用 awk,但日期格式会影响输出
【问题讨论】: