UNIX programming

和自甴很熟 提交于 2019-12-13 10:30:33

问题


Hi i want to convert UNIX date to normal date (YYYY-MM-DD)

22222,0,0,0,14387
33333,0,0,0,14170
44444,0,0,0,14244
55555,0,0,0,14190
66666,0,0,0,14528
77777,0,0,0,14200
88888,0,0,0,0
99999,0,0,0,0

here 5th column represents UNIX date

i want to convert into

22222,0,0,0,2009-05-23

and similarly remaining rows

can any body help me


回答1:


A simple awk script ought to do it

awk -F, 'BEGIN{OFS=","} { print $1,$2,$3,$4,strftime("%Y-%m-%d",$5) }' myFile.txt

Cheers.

EDIT:
You're not using unix timestamps, but I checked your data, and it appears you're using days since the epoch, so here goes:

awk -F, 'BEGIN{OFS=","} { print $1,$2,$3,$4,strftime("%Y-%m-%d",$5*86400) }' myFile.txt


来源:https://stackoverflow.com/questions/3335729/unix-programming

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!