I have a file which contains timestamp and date in the second column. If the line contains one of the word then it need to be replace like below.
File:
a smallint
b timestamp
c date
d varchar
O/P:
a smallint
dateformat(b,'YYYY-MM-DD HH:NN:SS.sss')
dateformat(c.'YYYY-MM-DD')
d varchar
If I execute this below command as a single awk then I am getting output but if I use else condition then I am getting error.
awk '{if ($2=="timestamp") {$3="dataformat("; }; print $3 $1 ",'\''YYYY-MM-DD HH'\:'NN'\:'SS'\.'sss)" else ($2=="date") {$3="dataformat("; }; print $3 $1 ",'\''YYYY-MM-DD)" }' test.out
Error:
awk: {if ($2=="timestamp") {$3="dataformat("; }; print $3 $1 ",'YYYY-MM-DD HH:NN:SS.sss)" else ($2=="date") {$3="dataformat("; }; print $3 $1 ",'YYYY-MM-DD)" }
awk: ^ syntax error