用sed替换文件中的特定模式或替换

用户2952821

在我的站点地图文件中,我想用_(下划线)替换:(冒号)。但是我不想替换诸如时间戳记之类的文件中的other。

我的线

    <sitemap><loc>http://www.example.com/sitemap_2014-09-27_09:42:43_1.xml.gz</loc>
<lastmod>2014-09-27 09:42:43</lastmod></sitemap>

在这一行中,“ sitemap_2014-09-27_09:42:43_1.xml.gz”应变为“ sitemap_2014-09-27_09_42_43_1.xml.gz”,但时间戳不会影响。

我是sed和pattern的新手。有人可以提供sed或replace或任何其他linux命令来替换文件中的此模式。

阿维纳什·拉吉(Avinash Raj)

您可以尝试使用此GNU sed命令,

sed -r 's/([^ ])([0-9]{2}):([0-9]{2}):([0-9]{2})/\1\2_\3_\4/g' file

通过基本的sed,

sed 's/\([^ ]\)\([0-9]\{2\}\):\([0-9]\{2\}\):\([0-9]\{2\}\)/\1\2_\3_\4/g' file

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章