How can i change the date format to 24 hours in a text file via shell.
cat data.txt
/stem/1 sts1033 08/29/2022 09:05:48 PM OX crN 51 Backup
/stem/2 sts1033 09/05/2022 09:05:18 PM OY crN 507 Backup
/stem/3 sts1033 09/12/2022 09:16:14 PM OX crN 5123 Backup
expected output-
/stem/1 sts1033 08/29/2022 21:05:48 OX crN 51 Backup
/stem/2 sts1033 09/05/2022 21:05:18 OY crN 507 Backup
/stem/3 sts1033 09/12/2022 21:16:14 OX crN 5123 Backup
CodePudding user response:
Use dateutils
:
dateconv -S -i '%m/%d/%Y %I:%M:%S %p' -f '%m/%d/%Y %H:%M:%S' < infile
Output:
/stem/1 sts1033 08/29/2022 21:05:48 OX crN 51 Backup
/stem/2 sts1033 09/05/2022 21:05:18 OY crN 507 Backup
/stem/3 sts1033 09/12/2022 21:16:14 OX crN 5123 Backup