小编She*_*Psy的帖子

使用awk将月份从Aaa转换为xx

我试图报告每个日期创建的文件数.我可以用这个小衬里做到这一点:

ls -la foo*.bar|awk '{print $7, $6}'|sort|uniq -c
Run Code Online (Sandbox Code Playgroud)

我也得到很多fooxxx.bar文件是如何被创建日期列表,但当月的格式为:AAA(即:4月),我想XX(即:04).

我觉得答案就在这里:

awk '
BEGIN{
   m=split("Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec",d,"|")
   for(o=1;o<=m;o++){
      months[d[o]]=sprintf("%02d",o)
    }
format = "%m/%d/%Y %H:%M"
}
{
split($4,time,":")
date = (strftime("%Y") " " months[$2] " " $3 " " time[1] " " time[2] " 0")
print strftime(format, mktime(date))
}'
Run Code Online (Sandbox Code Playgroud)

但是不知道我需要剥离什么,也不知道如何将7美元转移到我开辟的任何东西以将4月转换为04.

谢谢!

awk type-conversion

4
推荐指数
2
解决办法
3448
查看次数

标签 统计

awk ×1

type-conversion ×1