[英]Replace string and include date inside all .html files within a directory
我正在寻找bash代码将所有.html文件中的所有<title>XXX</title>
替换为<title>XXX - YYY $Date</title>
我想出的是,使用sed是:
sed -i "s/</title>/ - YYY 'date'/g" /home/mirror/*
然而,这并没有实现.html要求,我无法让它工作,我要么得到
sed: no imput files
要么
-bash: s/</title>/ - YYY 'date'/g: No such file or directory
结构是:
/home/mirror/
├── images
├── archive
│ └── index.html
│ └── 2.html
├── index.html
├── 2.html
├── style.css
└── scripts.js
我怎样才能做到这一点?
你需要find
通过目录递归:
find /home/mirror -name '*.html' -exec sed -i "s@</title>@ - YYY $Date</title>@g" {} +
注意我用“$ Date”替换了“'date'”,因为这就是你想要添加的内容。 我还使用@
而不是/
作为sed s
分隔符,以避免来自</title>
部分的干扰。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.