sed - Less ugly way to use sed to simply include a new line?
问题描述
There are a lot of guides, handbooks, fast-guides, question/answers about it: no one are simple and objective...
It is a classical problem, near all text editors crashes with big files XML or HTML "all in one line", so we need to decide what tag will recive the \n
and replace all occurences of <tag
by \n<tag
... so simple. Why it is not simple to do by terminal?
The best question/answer about this case not solves: Bash: How can I replace a string by new line in osx bash?
Example using that solution: sed 's/<article/\'$'\n\n<article/g' file.htm
not works, need some more exotical syntax, so it is not simple as I solicitated in this question.
So, this quetion is not about "any solution", but about "some simple/elegant solution".
解决方案
如果我了解您在寻找什么,您可以尝试以下方法:
sed 's/<tag>/\n<tag>/g' file.htm
这与您链接的答案非常接近。它在我看来已经很简单了,它用换行符替换标签并再次写入标签。但是,在您的情况下,我不需要这个“$”。
推荐阅读
- javascript - 如何从失败的获取请求中获取完整的错误?
- javascript - 带有 Websocket 或 Socket.io 的 Vue.js 实时图表
- swiftui - 如何访问类中的全局环境对象?
- firebase - Google Firebase 身份验证模拟器始终注销用户,而不是与生产隔离
- apache - htaccess 重定向查询字符串,但已编码?到 &
- html - 如何获取文本框输入旁边的 JQuery DatePicker 图标?
- swift - CoreBluetooth 只能在连接状态下接受命令
- wordpress - 在 wordpress 中使用 update_option 只更新一个值
- python - 当我期望它返回 true 时,isinstance 返回 False
- python - 使用 python 将 24 列转置为一列(24 行)并对值进行排序