例如,要在字符串:20061121164330中插入符号,使之变成日期格式:2006-11-21 16:43:30,可以有如下的几种方法可供参考。
方法一:
复制代码 代码如下:
#echo '20061121164330' |
sed -r 's/^(.{4})(.{2})(.{2})(.{2})(.{2})(.{2})$/1-2-3 4:5:6/g'
方法二:
复制代码 代码如下:
#echo "20061121155230" | sed 's,(.{4})(.{2})(.{2})(.{2})(.{2})(.{2}),1-2-3 4:5:6,'
方法三:
复制代码 代码如下:
#echo "20061121155230" |
linuxjishu/13830.html target=_blank class=infotextkey>awk 'BEGIN{FS=""}{print $1$2$3$4"-"$5$6"-"$7$8" "$9$10":"$11$12":"$13$14}'