gpt4 book ai didi

html - 在每个 unix GREP 结果周围添加 HTML 标签

转载 作者:搜寻专家 更新时间:2023-10-31 22:02:31 25 4
gpt4 key购买 nike

我正在编写脚本以从日志文件中获取某些文本并将其发布到 html 文件中。我遇到的问题是我希望 grep 的每个结果都在 <p></p> 中。标签。

这是我目前所拥有的:

cat my.log | egrep 'someText|otherText' | sed 's/timestamp//'

最佳答案

使用egrepsed

您目前拥有:

$ echo 'timestamp otherText' | egrep 'someText|otherText' | sed 's/timestamp//'
otherText

要在文本周围放置段落标记,只需向 sed 命令添加一个替换:

$ echo 'timestamp otherText' | egrep 'someText|otherText' | sed 's/timestamp//; s|.*|<p>&</p>|'
<p> otherText</p>

使用awk

$ echo 'timestamp otherText' | awk '/someText|otherText/{sub(/timestamp/, ""); print "<p>" $0 "</p>"}'
<p> otherText</p>

或者,从文件 my.log 获取输入:

awk '/someText|otherText/{sub(/timestamp/, ""); print "<p>" $0 "</p>"}' my.log

关于html - 在每个 unix GREP 结果周围添加 HTML 标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28423315/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com