日期輸出格式轉換

来源:互联网 发布:淘宝店访客量怎么提高 编辑:程序博客网 时间:2024/06/17 07:02

a.txt内容如下
1,asdqwezxc123,2010-01-01 00:00:00
2,ertyeshthgds2,2010-02-02 00:00:00
.

如何将最后一个逗号后面的 2010-01-01 00:00:00
转换成20100101,并复制一份

结果为:
1,asdqwezxc123,20100101,2010-01-01 00:00:00
2,ertyeshthgds2,20100202,2010-02-02 00:00:00

 

方法1:sed 's//([0-9]*/)-/([0-9]*/)-/([0-9]*/)//1/2/3,&/g'  a.txt     (思路相當巧妙)

方法2: awk -F, '{x=substr($3,1,4)substr($3,6,2)substr($3,9,2)}{print $1,$2,x,$3}' a.txt  (常規思路,字符串截取)