epoch conversion

I need to convert an epoch time from a file into a standard UTC time and output it in the same format but I'm not sure what's the best approach

here's the input file and the bold part is what I need to convert.

1,1,"sys1",60,300000
2,"E:",286511144960
3,1251194521,"E:",0,0
3,1251194581,"E:",8,0
3,1251194641,"E:",17,0
3,1251194701,"E:",8,0
3,1251194761,"E:",25,0
3,1251194821,"E:",34,0
3,1251194881,"E:",145,0
3,1251194941,"E:",1646,0
3,1251195001,"E:",8,0

I want the output file to look like this

1,1,"sys1",60,300000
2,"E:",286511144960
3,Tue Aug 25 11:02:01 2009,"E:",0,0
3,Tue Aug 25 11:03:01 2009,"E:",8,0
3,Tue Aug 25 11:04:01 2009,"E:",17,0
3,Tue Aug 25 11:05:01 2009,"E:",8,0
3,Tue Aug 25 11:06:01 2009,"E:",25,0
3,Tue Aug 25 11:07:01 2009,"E:",34,0
3,Tue Aug 25 11:08:01 2009,"E:",145,0
3,Tue Aug 25 11:09:01 2009,"E:",1646,0
3,Tue Aug 25 11:10:01 2009,"E:",8,0

So I googled around and wrote some lines but I don't think it's the way to do it.

##############################################################
#!/bin/ksh

#skip 1st 2 lines and grab the epoch time
tail +3 file1| awk -F',' '{print $2}' > /temp/time

## replace the epoch time with UTC
for time in `cat /temp/time| awk '{print $1}'`
do
perl -e 'print scalar localtime ('$time'), "\n"'

done

rm /temp/time
##############################################################

I now have the time converted but how do I output it in the same format ?
I don't script too often as you can see and would appreciate assistance.

Cheers.
G

Try something like this :


head -2 inputfile.txt > op.txt

for i in `tail +3 rem.txt`
do
time=`echo $i | awk -F, '{ print $2}'`
con=`perl -e 'print scalar localtime ('$time')'`
grep "$time" inputfile.txt | sed s/"$time"/"$con"/ >> op.txt
done

Brilliant. You're a genius. I get it. Gotta learn more and practice.
G