awk 'BEGIN{ FS=OFS=","
n=split("4,5,7,13,19", f) # array of input field numbers
}
{ for(i=1; i<=n; i++) if($f[i]) $f[i] = dconv($f[i]); print
}
function dconv(x) {
YY=substr(x, 1, 4)
mm=substr(x, 5, 2)
dd=substr(x, 7, 2)
hh=substr(x, 9, 2)
nn=substr(x,11, 2)
ss=substr(x,13, 2)
return dd"-"mm"-"YY" "hh":"nn":"ss
}' file
Abaixo, é (fundamentalmente) o mesmo script, com mais uma matriz (e sem a função)
awk 'BEGIN{ FS=OFS=","
nf=split("4,5,7,13,19", f) # array of input field numbers
nd=split(",7,2,-,5,2,-,1,4, ,9,2,:,11,2,:,13,2", d) # array of date subfield info (in output order): prefix(out),pos(in),len(in)
}
{ for(i=1; i<=nf; i++){
if($f[i]) {
fmod=""
for(j=1; j<=nd; j+=3) fmod=fmod sprintf("%s", d[j] substr($f[i], d[j+1], d[j+2]))
$f[i] = fmod
}
} print
}' file