3

I have a input a like below which having epoch and a number in some 2nd, 3rd columns in random.I am trying to the convert the epoch dates by using awk built-in function strftime() and it replace the values which is not in epoch value.

I tried using the below one but I don't get my desired output.

awk '{ print  $1 strftime("%c",$2) strftime("%c",$3)  }' test.txt

Input:-

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 

Expected Output Sample Format: Need to replace the epoch value to date below mention format in the same file

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
0
7
$ 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
3
  • Thanks Mortan,its working,can i skip the first 5 line and tell awk to process from 6th file by using FNR or NR,i tried not working in the above script,in my file record will starts from 6th line above that there are some header and information,so need to skip that in above
    – Renga
    Nov 25 at 13:01
  • You're welcome. Sure, you can do just about anything you like. Next time you ask a question though make sure to include information like that in your question and show it in your sample input/output, don't add it later in comments as chameleon questions are strongly discouraged.
    – Ed Morton
    Nov 25 at 13:04
  • Yeah thanks Alot..tried with NR and working Fine
    – Renga
    Nov 25 at 13:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.