如何匹配日期 mm/dd/yyyy [英] How to match date mm/dd/yyyy
本文介绍了如何匹配日期 mm/dd/yyyy的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
给定以下输入
506028500,1820196768,43,0,84552257, ,1,-71.16,42.42,04/26/2012,
我想过滤行尾的日期,所以我可以把它的mm/dd/yyyy格式改成MySQL日期格式yyyy-mm-dd:
I want to filter the date at the end of the row, so I can change its mm/dd/yyyy format into MySQL date format yyyy-mm-dd:
我试图匹配行末尾的日期,首先删除了尾随的,"(逗号).
I am trying to match the date at the end of the row having first removed the trailing ',' (comma).
{
s/,$//g
/\([0-9][0-9]\)\/\([0-9][0-9]\)\/\([0-9][0-9][0-9][0-9]\)$/=
}
我收到 12847,但我期待收到 04262012.
I'm getting 12847, but am expecting 04262012.
我做错了什么,我什至无法匹配那里的日期?
What am I doing wrong, that I can't even match the date that's there?
谢谢.
推荐答案
这可能对你有用:
echo "506028500,1820196768,43,0,84552257, ,1,-71.16,42.42,04/26/2012," |
sed 's|,\(..\)/\(..\)/\(....\),$|,\3-\2-\1,|'
506028500,1820196768,43,0,84552257, ,1,-71.16,42.42,2012-26-04,
如果您只想要日期:
echo "506028500,1820196768,43,0,84552257, ,1,-71.16,42.42,04/26/2012," |
sed 's|.*,\(..\)/\(..\)/\(....\),$|\3-\2-\1|'
2012-26-04
这篇关于如何匹配日期 mm/dd/yyyy的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文