【问题标题】:replace .php file extensions with .html extension using unix使用 unix 将 .php 文件扩展名替换为 .html 扩展名
【发布时间】:2012-10-26 01:35:44
【问题描述】:

我正在创建一个构建脚本以在生成 .html 文件后对其进行扫描,但我似乎不知道如何使其工作。这是一个sn-p:

for PAGE in ${PAGES[@]}
do
    echo "\t\t\t- $DIR_PRE$PAGE.html"
    echo "\t\t\t- cleaning links in $DIR_PRE$PAGE.html"
    php helper.php output lang=$GET+environment=prod+page=$PAGE > $SITE/$DIR_PRE$PAGE.html
    find * -name \*.html -print0 | xargs -0 sed --in-place -e 's~.php~.html~g'
done

最后一个 find 命令应该在 .html 文件中找到带有 .php 扩展名的链接并将其替换为 .html 但我收到此错误:

sed: 非法选项 -- - 用法:sed 脚本 [-Ealn] [-i 扩展名] [文件 ...] sed [-Ealn] [-i extension] [-e script] ... [-f script_file] ... [file ...] - wiiu.html

【问题讨论】:

    标签: unix build-script


    【解决方案1】:

    如果要将当前目录下的所有.html文件递归重命名为.php:

    find . -name "*.html" -exec rename .html .php {} \;

    编辑:误解了这个问题。您可以使用 sed 替换文件中的字符串:

    sed -i 's/.html/.php/g' *.html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-06
      • 2014-12-06
      相关资源
      最近更新 更多