html - 如何用shell脚本替换html文件中的多行文本?
问题描述
我有一个 html 文件,我想在其中使用 shell 脚本使用函数替换样式sed
。我想更换:
pre {
font-size: inherit;
line-height: inherit;
}
和:
pre {
font-size: 18px;
/*line-height: inherit;*/
}
我尝试了以下方法:
sed -i 's/pre {\n font-size: inherit;\n line-height:
inherit;\n}/pre {\n font-size: 18px;\n \/\*line-height:
inherit;\*\/\n}/g' /path/file.html
它运行没有任何错误,但不会替换文本。请注意,我包含用于微调文本模式的选项卡。我正在开发 ubuntu 18。
任何建议将不胜感激。
解决方案
您可以在 sed 中使用匹配的模式引用,例如:
sed -i 's/line-height: inherit;/\/*&*\//g' /path/file.html
在这里,我们使用
line-height: inherit;
匹配搜索模式。您也可以将其扩展为正则表达式&
用于引用匹配的文本,我们将\/*
and*\/
作为封闭字符
推荐阅读
- ios - 将表格视图单元格从一个表格视图移动到新的表格视图
- java - 随机不打印正确的最大值和最小值
- powershell - Powershell 字符串替换掩码变量
- javascript - Vuejs SPA 动态主题
- linux - 如何使用 GET 将多个参数发送到带有端口号的 url
- android - 了解 Android-Java 中的 res 文件夹(react-native 预期)
- arrays - 评估for循环中的条件时Julia中的UndefVarError
- node.js - sequalize.js - 如何从 sequelize 生成的查询中删除双引号
- scheme - 方案中的条件定义(lisp)
- python - 如何从数据库中使用 python 创建家谱(谱系)?