regex - Unix pattern datetime match -
i want edit line:
1987,4,12,31,4,1987-12-31 00:00:00.0000000,ua,19977,ua,,631,12197,1219701,31703,hpn,white plains, ny,ny,36,new york,22,13930,1393001,30977,ord,chicago\, il,il,17,illinois,41,756,802,483.2,6,6,0,0,0700-0759,,,,,914,938,600.8,24,24,1,1,0900-0959,0,,0,138,156,,1,738,3,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,us1njbg0005,us1ilck0027,,,,,,,,,,,,,1987-12-31 08:09:12.0000000,519494350
and want output :
1987,4,12,31,4,1987-12-31 00:00:00.000,ua,19977,ua,,631,12197,1219701,31703,hpn,white plains, ny,ny,36,new york,22,13930,1393001,30977,ord,chicago\, il,il,17,illinois,41,756,802,483.2,6,6,0,0,0700-0759,,,,,914,938,600.8,24,24,1,1,0900-0959,0,,0,138,156,,1,738,3,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,us1njbg0005,us1ilck0027,,,,,,,,,,,,,1987-12-31 08:09:12.000,519494350
i want find each pattern of: ****-**-** **:**:**.0000000
and erase last 4 digits ( 0000 ) ****-**-** **:**:**.000.
if helpful date format in 6th columns , n-1 columns.
to value of 6th column , erase last 4 digits can use:
awk -f, '{print substr($6, 0, length($6)-4) }'
similarly, n-1 column can reached by:
awk -f, '{print substr( $(nf-1), 0, length($(nf-1))-4) }'
edit:
to replace values in columns, still print use:
awk 'begin{ fs=","; ofs=","} { $6=substr($6, 0, length($6)-4); $(nf-1)=substr( $(nf-1), 0,length($(nf-1))-4); print $0}'
Comments
Post a Comment