Help changing date format in the nth field

Hi,

I have two (2) things that I want to do.

First is to change the date format that is in the nth field from MM/DD/YY to YY/MM/DD. Preferably, I wish I know how to make it a 4-digit year but I don't. Problem is I can only assume it is a 20 century

Second is somehow know how to figure out what is the date format on that field before changing it to YYYY/MM/DD.

I would have prefer to use awk/sed or both but I can't work out the syntax to use so I've scripted it instead. I saw some example on using awk to search and replace the nth field but I can't find an example where I have to swap the 3 date values.

Below is the test file that I am wanting to change the date format:

$: cat xx.out
Objects in the image backed up on 04/21/15 00:30:18 for filespace /test_vol_abcd in node BOS123456:
Objects in the image backed up on 05/21/15 00:30:14 for filespace /test_vol_abcd in node BOS123456:
Objects in the image backed up on 21/01/16 00:30:13 for filespace /test_vol_abcd in node BOS123456:
Objects in the image backed up on 21/01/17 00:30:15 for filespace /test_vol_abcd in node BOS123456:
Objects in the image backed up on 21/02/16 00:30:28 for filespace /test_vol_abcd in node BOS123456:
Objects in the image backed up on 21/02/17 00:30:26 for filespace /test_vol_abcd in node BOS123456:
Objects in the image backed up on 21/03/16 00:30:30 for filespace /test_vol_abcd in node BOS123456:
Objects in the image backed up on 21/03/17 00:30:05 for filespace /test_vol_abcd in node BOS123456:
Objects in the image backed up on 21/04/16 00:30:03 for filespace /test_vol_abcd in node BOS123456:
Objects in the image backed up on 21/04/17 00:30:23 for filespace /test_vol_abcd in node BOS123456:
Objects in the image backed up on 21/05/16 00:30:19 for filespace /test_vol_abcd in node BOS123456:
Objects in the image backed up on 21/05/17 00:30:23 for filespace /test_vol_abcd in node BOS123456:
Objects in the image backed up on 21/06/15 00:30:13 for filespace /test_vol_abcd in node BOS123456:
Objects in the image backed up on 21/06/16 00:30:20 for filespace /test_vol_abcd in node BOS123456:
Objects in the image backed up on 21/07/15 00:30:26 for filespace /test_vol_abcd in node BOS123456:
Objects in the image backed up on 21/07/16 00:30:02 for filespace /test_vol_abcd in node BOS123456:
Objects in the image backed up on 21/08/16 00:30:28 for filespace /test_vol_abcd in node BOS123456:
Objects in the image backed up on 21/09/16 00:30:28 for filespace /test_vol_abcd in node BOS123456:
Objects in the image backed up on 21/10/15 00:30:12 for filespace /test_vol_abcd in node BOS123456:
Objects in the image backed up on 21/10/16 00:30:25 for filespace /test_vol_abcd in node BOS123456:
Objects in the image backed up on 21/11/15 00:30:19 for filespace /test_vol_abcd in node BOS123456:
Objects in the image backed up on 21/11/16 00:30:25 for filespace /test_vol_abcd in node BOS123456:
Objects in the image backed up on 21/12/15 00:30:26 for filespace /test_vol_abcd in node BOS123456:
Objects in the image backed up on 21/12/16 00:30:23 for filespace /test_vol_abcd in node BOS123456:
Objects in the image backed up on 25/10/16 11:36:14 for filespace /test_vol_abcd in node BOS123456:
Objects in the image backed up on 30/09/15 16:13:45 for filespace /test_vol_abcd in node BOS123456:

Below is the script:

#!/bin/ksh

while read line
do
   txt1=`echo $line | cut -c 1-33`
   txt2=`echo $line | cut -c 44-`
   date_01=`echo $line | cut -c 35-42`
   date_02=`echo $date_01 | awk -F"/" '{ printf "%s/%s/%s" , $3,$2,$1 }'`
   #echo "- date_01 = $date_01 // - date_02 = $date_02"
   echo "$line"
   echo "---> $txt1 $date_02 $txt2"
done < xx.out

And below is the test run of the script:

$: ./y.ksh
Objects in the image backed up on 04/21/15 00:30:18 for filespace /test_vol_abcd in node BOS123456:
---> Objects in the image backed up on 15/21/04 00:30:18 for filespace /test_vol_abcd in node BOS123456:
Objects in the image backed up on 05/21/15 00:30:14 for filespace /test_vol_abcd in node BOS123456:
---> Objects in the image backed up on 15/21/05 00:30:14 for filespace /test_vol_abcd in node BOS123456:
Objects in the image backed up on 21/01/16 00:30:13 for filespace /test_vol_abcd in node BOS123456:
---> Objects in the image backed up on 16/01/21 00:30:13 for filespace /test_vol_abcd in node BOS123456:
Objects in the image backed up on 21/01/17 00:30:15 for filespace /test_vol_abcd in node BOS123456:
---> Objects in the image backed up on 17/01/21 00:30:15 for filespace /test_vol_abcd in node BOS123456:
Objects in the image backed up on 21/02/16 00:30:28 for filespace /test_vol_abcd in node BOS123456:
---> Objects in the image backed up on 16/02/21 00:30:28 for filespace /test_vol_abcd in node BOS123456:
Objects in the image backed up on 21/02/17 00:30:26 for filespace /test_vol_abcd in node BOS123456:
---> Objects in the image backed up on 17/02/21 00:30:26 for filespace /test_vol_abcd in node BOS123456:
Objects in the image backed up on 21/03/16 00:30:30 for filespace /test_vol_abcd in node BOS123456:
---> Objects in the image backed up on 16/03/21 00:30:30 for filespace /test_vol_abcd in node BOS123456:
Objects in the image backed up on 21/03/17 00:30:05 for filespace /test_vol_abcd in node BOS123456:
---> Objects in the image backed up on 17/03/21 00:30:05 for filespace /test_vol_abcd in node BOS123456:
Objects in the image backed up on 21/04/16 00:30:03 for filespace /test_vol_abcd in node BOS123456:
---> Objects in the image backed up on 16/04/21 00:30:03 for filespace /test_vol_abcd in node BOS123456:
Objects in the image backed up on 21/04/17 00:30:23 for filespace /test_vol_abcd in node BOS123456:
---> Objects in the image backed up on 17/04/21 00:30:23 for filespace /test_vol_abcd in node BOS123456:
Objects in the image backed up on 21/05/16 00:30:19 for filespace /test_vol_abcd in node BOS123456:
---> Objects in the image backed up on 16/05/21 00:30:19 for filespace /test_vol_abcd in node BOS123456:
Objects in the image backed up on 21/05/17 00:30:23 for filespace /test_vol_abcd in node BOS123456:
---> Objects in the image backed up on 17/05/21 00:30:23 for filespace /test_vol_abcd in node BOS123456:
Objects in the image backed up on 21/06/15 00:30:13 for filespace /test_vol_abcd in node BOS123456:
---> Objects in the image backed up on 15/06/21 00:30:13 for filespace /test_vol_abcd in node BOS123456:
Objects in the image backed up on 21/06/16 00:30:20 for filespace /test_vol_abcd in node BOS123456:
---> Objects in the image backed up on 16/06/21 00:30:20 for filespace /test_vol_abcd in node BOS123456:
Objects in the image backed up on 21/07/15 00:30:26 for filespace /test_vol_abcd in node BOS123456:
---> Objects in the image backed up on 15/07/21 00:30:26 for filespace /test_vol_abcd in node BOS123456:
Objects in the image backed up on 21/07/16 00:30:02 for filespace /test_vol_abcd in node BOS123456:
---> Objects in the image backed up on 16/07/21 00:30:02 for filespace /test_vol_abcd in node BOS123456:
Objects in the image backed up on 21/08/16 00:30:28 for filespace /test_vol_abcd in node BOS123456:
---> Objects in the image backed up on 16/08/21 00:30:28 for filespace /test_vol_abcd in node BOS123456:
Objects in the image backed up on 21/09/16 00:30:28 for filespace /test_vol_abcd in node BOS123456:
---> Objects in the image backed up on 16/09/21 00:30:28 for filespace /test_vol_abcd in node BOS123456:
Objects in the image backed up on 21/10/15 00:30:12 for filespace /test_vol_abcd in node BOS123456:
---> Objects in the image backed up on 15/10/21 00:30:12 for filespace /test_vol_abcd in node BOS123456:
Objects in the image backed up on 21/10/16 00:30:25 for filespace /test_vol_abcd in node BOS123456:
---> Objects in the image backed up on 16/10/21 00:30:25 for filespace /test_vol_abcd in node BOS123456:
Objects in the image backed up on 21/11/15 00:30:19 for filespace /test_vol_abcd in node BOS123456:
---> Objects in the image backed up on 15/11/21 00:30:19 for filespace /test_vol_abcd in node BOS123456:
Objects in the image backed up on 21/11/16 00:30:25 for filespace /test_vol_abcd in node BOS123456:
---> Objects in the image backed up on 16/11/21 00:30:25 for filespace /test_vol_abcd in node BOS123456:
Objects in the image backed up on 21/12/15 00:30:26 for filespace /test_vol_abcd in node BOS123456:
---> Objects in the image backed up on 15/12/21 00:30:26 for filespace /test_vol_abcd in node BOS123456:
Objects in the image backed up on 21/12/16 00:30:23 for filespace /test_vol_abcd in node BOS123456:
---> Objects in the image backed up on 16/12/21 00:30:23 for filespace /test_vol_abcd in node BOS123456:
Objects in the image backed up on 25/10/16 11:36:14 for filespace /test_vol_abcd in node BOS123456:
---> Objects in the image backed up on 16/10/25 11:36:14 for filespace /test_vol_abcd in node BOS123456:
Objects in the image backed up on 30/09/15 16:13:45 for filespace /test_vol_abcd in node BOS123456:
---> Objects in the image backed up on 15/09/30 16:13:45 for filespace /test_vol_abcd in node BOS123456:

At the moment, I am wanting to know if there is any way I can do what the script is doing by simply using awk?

It would be a bonus if someone can advise how to be able to test a field and work out what is its date format. The reason for this is 'coz if you would check on the test data, the first two lines has a MM/DD/YY format compare to the rest of them. Somewhere along the line, someone has changed the date format :frowning:

Any advice much appreciated. Thanks in advance.

Try

awk '{split ($8, T, "/"); $8=T[3] "/" T[1] "/" T[2]} 1' file2
Objects in the image backed up on 15/04/21 00:30:18 for filespace /test_vol_abcd in node BOS123456:
Objects in the image backed up on 15/05/21 00:30:14 for filespace /test_vol_abcd in node BOS123456:

Bonus question: You can't. How would you tell month from day in 11/10/17 ?