Shell problem case and three Musketeers awk and sed settlement practice

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.