我怎样才能提取只使用SED或者grep的格式化的日期字段? [英] How can I extract just the formatted date fields using sed or grep?

查看:112
本文介绍了我怎样才能提取只使用SED或者grep的格式化的日期字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个grep或者sed的声明只会从这句话拿出日期:

I need a grep or sed statement that would only take out the dates from this statement:

echo 'asdfdsfa asdfs 12-Dec-13 asdasd asdf 11-Jan-12 asdasd' 

所以答案应该是这样的:

So answer should be something like this:

12-Dec-13 11-Jan-12

我已经得到了足够让 12日 - 12月13 asdasd航空自卫队11-JAN-12 ,但我不能删除的日期之间的内容。是否有可能使用一个sed语句来保持第一字和使用的空间去展示这是硬道理硬道理?结果应该保持相同。

I have gotten far enough to get 12-Dec-13 asdasd asdf 11-Jan-12, but I cant remove the content between the dates. Is it possible to use a sed statement to keep the first word and last word using space to show which is the last word? The result should remain the same.

推荐答案

试试这个:

echo 'asdfdsfa asdfs 12-Dec-13 asdasd asdf 11-Jan-12 asdasd'  | sed 's: :\n:g' | grep ^[0-9]

这篇关于我怎样才能提取只使用SED或者grep的格式化的日期字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆