Date conversion and Format

Hello ,
I have a record in below format

Hostname | Query: 0 | Release: 0 | files: 2 | Files_examined: 2 | SET timestamp=1396778638; | select * from test 

I need output in below format

Hostname | 0 | 0 | 2 | 2 | 04/06/2014|03:03:58 | select * from test 

I was able to get above output using two different command

Command - 1

 
 sed -e 's/Query://g' -e 's/Release://g' -e 's/files://g' -e s'/Files_examined://g' -s s'/SET timestamp=//g' 

Command -2

 date -d @1396778638 "+%m/%d/%Y|%T"

which gives me output of

 
04/06/2014|03:03:58

Looking some help in combining these two commands as one and get the out as above , If my above approach is wrong or would take lot of CPU for larger records . Please feel free to change the code .

Assuming that your record or records are in a file named file , you could try something like:

#!/bin/ksh
IAm=${0##*/}
tmpfile="$IAm.$$"
trap 'rm -f "$tmpfile"' EXIT
awk -F '( SET timestamp=)|(; )' -v tf="$tmpfile" '
{	system("date -d @" $2 " +\"%m/%d/%Y|%T\" > " tf)
	getline result < tf
	close(tf)
	$2 = result
	gsub(/[_[:alpha:]]*: /, "")
	print
}' file