shell問題案例及三劍客awk與sed解決實踐

來源:互聯網
上載者:User

標籤:sed   awk   

20150418周末小題未經處理資料: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期望結果: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解決實踐:來自營運21期悠久之翼 群內分享[[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/,"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+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


本文出自 “老男孩linux營運” 部落格,請務必保留此出處http://oldboy.blog.51cto.com/2561410/1636008

shell問題案例及三劍客awk與sed解決實踐

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.