我正在清理很多markdown文件以将它们导入Pelican(一个静态网站生成器)。编译时,我得到有关多个文件中日期格式的错误。我需要做的是保留日期(yyyy-mm-dd)并删除它后面的行尾。这是最后一次尝试,我用sed
和正则表达式制作:在匹配正则表达式之后删除文件结尾保持多个文件中匹配的表达式(sed?)
sed -i "s/\(\d{4}-\d{2}-\d{2}\)\*/\1 /g" *.md
我的希望是,SED将采取括号内的整个图案为1
,然后把它作为替换字符串。
这是错误的例子(所有的数字变化):
ERROR: Could not process ./2010-12-28-the-open-internet-a-case-for-net-neutrality.html.md
| ValueError: '2010-12-28 21:22:00.000000000 +01:00 true' is not a valid date
ERROR: Could not process ./2011-05-27-two-one-must-read-internet-business-book.html.md
| ValueError: '2011-05-27 13:08:00.000000000 +02:00 true' is not a valid date
我环顾四周左右,但所有我发现是关于静态字符串,而我总是在变化。
感谢您的帮助。
也参见https://unix.stackexchange.com/questions/119905/why-does-my-regular -expression-work-in-x-but-in-y – Sundeep
很好的参考文章,谢谢@sundeep –