var1= date -d "19521029 1010" +"%Y-%m-%d %H:%M"
echo$var1
its working properly but date -d
inside awk is not working
file
KOD19|KAD37748|DEL37728|VIDYA|19521029 1010|201209111625
SASI19|NAS38228|DEL37728|KARTHIKA|19521029 0000|201308071912
RADHA94|VAS37748|DEL37728|LALINKA|19521029 0000|201407061815
First method
awk 'BEGIN {FS=OFS="|"} $5=date -d "$5"+"%Y-%m-%d %H:%M" {print}' file
second method
awk -F '|' '{$5=date -d $5+"%Y-%m-%d %H:%M"; {OFS="|"}; print}' file
Desired output
KOD19|KAD37748|DEL37728|VIDYA|1952-10-29 10:10|201209111625
SASI19|NAS38228|DEL37728|KARTHIKA|1952-10-29 10:10|201308071912
RADHA94|VAS37748|DEL37728|LALINKA|1952-10-29 10:10|201407061815
I want to convert the fifth column of "file" to user input date format. Actually column number and date formats are dynamic ie dt="%Y-%m-%d %H:%M" and num=$5 it will very depends on user requirement.