我有一个类似下面的输入,其中有纪元和随机的第二、第三列中的数字。我正在尝试使用 awk 内置函数 strftime() 来转换纪元日期,并替换不在其中的值纪元值。
我尝试使用下面的,但没有得到我想要的输出。
awk '{ print $1 strftime("%c",$2) strftime("%c",$3) }' test.txt
输入:-
h_RTGUSEQ_RTY_FILE_LIST_ODRF_XOB 0 0 11
TRF_RTGUSFX_RTY_FILE_LIST_XOB 0 0 11
TRF_RTGUSIG_RTY_FILE_LIST_XOB 0 0 11
NGU_AVM_DAILY_SCHEDULE_XOB 1617804000 1617804156 7
TRF_RTGUSIR_RTY_FILE_LIST_XOB 0 0 11
NGU_schedule_next 1614198958 1614198979 7
TCR_RTGUSCR_DSTGE_REPORT_XOB 1591171200 1591171268 7
YUI_RTGNLEQ_DB_CHK_RTYCYCLE_ARCHV_XOB 0 0 11
NGU_schedule_current 1614198946 1614198957 7
YUI_RTGNLEQ_Z_DUMMY_XOB 0 0 7
YUI_RTGNLEQ_Z_TRIGR_DSJ_XOB 0 0 11
YUI_RTGSGEQ_DB_CHK_RTYCYCLE_ARCHV_XOB 0 0 11
预期的输出样本格式:需要将同一文件中提到的格式中的纪元值替换为日期
h_RTGUSEQ_RTY_FILE_LIST_ODRF_XOB 0 0 11
TRF_RTGUSFX_RTY_FILE_LIST_XOB 0 0 11
TRF_RTGUSIG_RTY_FILE_LIST_XOB 0 0 11
NGU_AVM_DAILY_SCHEDULE_XOB 07 Apr 2021 09:04:00 AM 07 Apr 2021 09:04:36 AM 7
TRF_RTGUSIR_RTY_FILE_LIST_XOB 0 0 11
NGU_schedule_next 24 Feb 2021 02:02:58 PM 24 Feb 2021 02:02:19 PM 7
TCR_RTGUSCR_DSTGE_REPORT_XOB 03 Jun 2020 03:06:00 AM 03 Jun 2020 03:06:08 AM 7
YUI_RTGNLEQ_DB_CHK_RTYCYCLE_ARCHV_XOB 0 0 11
NGU_schedule_current 24 Feb 2021 02:02:46 PM 24 Feb 2021 02:02:57 PM 7
YUI_RTGNLEQ_Z_DUMMY_XOB 0 0 7
YUI_RTGNLEQ_Z_TRIGR_DSJ_XOB 0 0 11
YUI_RTGSGEQ_DB_CHK_RTYCYCLE_ARCHV_XOB 0 0 11
答案1
$ awk -v OFS='\t' '{
for (i=2; i<=3; i++) {
$i = ($i ? strftime("%d %b %Y %r",$i) : $i)
}
print
}' test.txt | column -s$'\t' -t
h_RTGUSEQ_RTY_FILE_LIST_ODRF_XOB 0 0 11
TRF_RTGUSFX_RTY_FILE_LIST_XOB 0 0 11
TRF_RTGUSIG_RTY_FILE_LIST_XOB 0 0 11
NGU_AVM_DAILY_SCHEDULE_XOB 07 Apr 2021 09:04:00 AM 07 Apr 2021 09:04:36 AM 7
TRF_RTGUSIR_RTY_FILE_LIST_XOB 0 0 11
NGU_schedule_next 24 Feb 2021 02:02:58 PM 24 Feb 2021 02:02:19 PM 7
TCR_RTGUSCR_DSTGE_REPORT_XOB 03 Jun 2020 03:06:00 AM 03 Jun 2020 03:06:08 AM 7
YUI_RTGNLEQ_DB_CHK_RTYCYCLE_ARCHV_XOB 0 0 11
NGU_schedule_current 24 Feb 2021 02:02:46 PM 24 Feb 2021 02:02:57 PM 7
YUI_RTGNLEQ_Z_DUMMY_XOB 0 0 7
YUI_RTGNLEQ_Z_TRIGR_DSJ_XOB 0 0 11
YUI_RTGSGEQ_DB_CHK_RTYCYCLE_ARCHV_XOB 0 0 11