简体   繁体   English

如何使用sed匹配“月日”年模式?

[英]How to use sed to match Month day year pattern?

I am working with large documents and I want to make two tasks, the first is to substitute all the dates that come in this way: "August 12 2014" or "January 31 1999" so I am using the following line in sed: 我正在处理大型文档,我想做两个任务,第一个是替换以这种方式出现的所有日期:“ 2014年8月12日”或“ 1999年1月31日”,因此我在sed中使用以下行:

s/\\(jan.\\|feb.\\|mar.\\|apr.\\|may\\|jun.\\|jul.\\|aug.\\|sep.\\|oct.\\|nov.\\|dec.\\) \\([0-9]\\|[0-9][0-9]\\) [1-9][0-9][0-9][0-9]/tokendate/g

However It does not take for example august, I know I could change aug. 然而,这并不需要例如八月,我知道我可以改变八月。 for august, but I'd like that sed match any string that begins with aug___ or sep____. 八月,但我希望sed匹配以aug___或sep____开头的任何字符串。

Thanks in advance for any help 预先感谢您的任何帮助

sed -r 's/(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)[a-z]* [0-9]{1,2} [1-9][0-9]{3}/tokendate/gi' file

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM