20150418 Weekend Quiz raw data: 17/apr/2015:09:29:24 +080017/apr/2015:09:30:26 +080017/apr/2015:09:31:56 + 080018/apr/2015:09:34:12 +080018/apr/2015:09:35:23 +080019/apr/2015:09:23:34 +080019/apr/ 2015:09:22:21 +080020/apr/2015:09:45:22 +0800 Expected results:2015-04-17 09:29:24+08002015-04-17 09:30:26+08002015-04-17 09:31:56+08002015-04-18 09:34:12+08002015-04-18 09:35:23+08002015-04-19 09:23:34+08002015-04-19 09:22:21+08002015-04-20 09:45:22+0800 solution Practice: From OPS 21 long wing Group sharing [email protected] ~]# cat oldboy.txt 17/apr/2015:09:29:24 +080017/apr/2015:09:30:26 +080017/apr/2015:09:31:56 +080018/apr/2015:09:34:12 +080018/apr/2015:09:35:23 +080019/apr /2015:09:23:34 +080019/apr/2015:09:22:21 +080020/apr/2015:09:45:22 +0800[[email protected] ~]# awk ' {sub (/apr/, "" "), Split ($0,array," [/: ] ") ;p rintf ("%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+08002015-04-17 09:30:26+08002015-04-17 09:31:56+08002015-04-18 09:34:12+08002015-04-18 09:35:23+08002015-04-19 09:23:34+08002015-04-19 09:22:21+08002015-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+08002015-04-17 09:30:26+08002015-04-17 09:31:56+08002015-04-18 09:34:12+08002015-04-18 09:35:23+ 08002015-04-19 09:23:34+08002015-04-19 09:22:21+08002015-04-20 09:45:22+0800
This article is from the "Old boy Linux ops" blog, please be sure to keep this source http://oldboy.blog.51cto.com/2561410/1636008
Shell problem case and three Musketeers awk and sed settlement practice