20150418周末小题 原始数据: 17/Apr/2015:09:29:24 +0800 17/Apr/2015:09:30:26 +0800 17/Apr/2015:09:31:56 +0800 18/Apr/2015:09:34:12 +0800 18/Apr/2015:09:35:23 +0800 19/Apr/2015:09:23:34 +0800 19/Apr/2015:09:22:21 +0800 20/Apr/2015:09:45:22 +0800 期望结果: 2015-04-17 09:29:24+0800 2015-04-17 09:30:26+0800 2015-04-17 09:31:56+0800 2015-04-18 09:34:12+0800 2015-04-18 09:35:23+0800 2015-04-19 09:23:34+0800 2015-04-19 09:22:21+0800 2015-04-20 09:45:22+0800 解决实践:来自运维21期悠久之翼 群内分享 [[email protected] ~]# cat oldboy.txt 17/Apr/2015:09:29:24 +0800 17/Apr/2015:09:30:26 +0800 17/Apr/2015:09:31:56 +0800 18/Apr/2015:09:34:12 +0800 18/Apr/2015:09:35:23 +0800 19/Apr/2015:09:23:34 +0800 19/Apr/2015:09:22:21 +0800 20/Apr/2015:09:45:22 +0800 [[email protected] ~]# awk ‘{sub(/Apr/,"04");split($0,array,"[/: ]") ;printf("%s-%s-%s %s:%s:%s%s\n",array[3],array[2],array[1],array[4],array[5],array[6],array[7])}‘ oldboy.txt 2015-04-17 09:29:24+0800 2015-04-17 09:30:26+0800 2015-04-17 09:31:56+0800 2015-04-18 09:34:12+0800 2015-04-18 09:35:23+0800 2015-04-19 09:23:34+0800 2015-04-19 09:22:21+0800 2015-04-20 09:45:22+0800 [[email protected] ~]# sed -nr ‘s#(..)/(...)/(....):(..):(..):(..) (.*)#\3-\2-\1 \4:\5:\6\7#;s#Apr#04#p‘ oldboy.txt 2015-04-17 09:29:24+0800 2015-04-17 09:30:26+0800 2015-04-17 09:31:56+0800 2015-04-18 09:34:12+0800 2015-04-18 09:35:23+0800 2015-04-19 09:23:34+0800 2015-04-19 09:22:21+0800 2015-04-20 09:45:22+0800
时间: 2024-10-14 17:00:36