Arrange date in a field

Hi all,

If I have a flat file
ID|Location|Date|Hostname|Age|Sex
1|SFO|06/02/24 12:12:34|hawkeye|35|M
2|LAX|06/02/24 13:12:35|sf49ers|30|M
3|OAK|06/02/25 11:12:36|goraiders|27|F
4|PIT|06/02/25 12:12:37|steeler|35|M

How can I create an output
1|SFO|02/24/2006 12:12:34|hawkeye|35|M
2|LAX|02/24/2006 13:12:35|sf49ers|30|M
3|OAK|02/25/2006 11:12:36|goraiders|27|F
4|PIT|02/25/2006 12:12:37|steeler|35|M

Thanks .

What was wrong with my code ??? it look right to me but it give me the error

datetime="`echo $3 | nawk '{n=split($1, da, "/"); print da[2]"/" da[3]"/20" da[1] " " $2}'`";

this is the error `(' is not expected.

if datetime is work then I solve my problem .

I test this and it works ???
echo '06/02/25 12:05:06' | nawk '{n=split($1, da, "/"); print da[2]"/" da[3]"/20" da[1] " " $2}'

Please knock me where i made mistake .
Thanks,

nawk 'BEGIN {FS="[ |/]"}
{
printf("%s|%s|%s/%s/%s %s",$1,$2,$4,$5,$3,$6);
for(i=7;i<=NF;i++)
{
printf("|%s",$i);
}
printf "\n";
}' filename

if you want to sort based on the date field, then append the following to end of above command.

| sort -t "|" -k 3.3

why not try this...

datetime=`echo "$3" | awk -F"/" '{ print $2"/"substr($3,1,2)"/20"$1 }'`

Oh, I would like to have the date field change as I want.

mgirinath, this one give me only the date
mahendramahendr, this one give me the out put the same as b4.

I want datetime field change from 06/02/25 11:12:36 to 02/25/2006 11:12:36
but my code got the error ? why syntax error is `(' is not expected

$ more tmp1
2|LAX|06/02/24 13:12:35|sf49ers|30|M
3|OAK|06/02/25 11:12:36|goraiders|27|F
1|SFO|06/02/24 12:12:34|hawkeye|35|M
4|PIT|06/02/25 12:12:37|steeler|35|M

$ nawk 'BEGIN {FS="[ |/]"}
{
printf("%s|%s|%s/%s/%s %s",$1,$2,$4,$5,$3,$6);
for(i=7;i<=NF;i++)
{
printf("|%s",$i);
}
printf "\n";
}' tmp1
2|LAX|02/24/06 13:12:35|sf49ers|30|M
3|OAK|02/25/06 11:12:36|goraiders|27|F
1|SFO|02/24/06 12:12:34|hawkeye|35|M
4|PIT|02/25/06 12:12:37|steeler|35|M

You can clearly see the date format changing to MM/DD/YY...

Is it not what you are looking for ?? what do you mean by same as b4 ?

I think the format of your flat file is different than what you have posted if it is not working....

OOPS Sorry...here is date and time...

date=`echo "$3" | awk -F"/" '{ print $2"/"substr($3,1,2)"/20"$1 }'`
time=`echo "$3" | awk '{ print $2 }'`
echo $date" "$time