加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

在每个unix GREP结果周围添加HTML标记

发布时间:2020-12-16 01:50:30 所属栏目:安全 来源:网络整理
导读:我正在编写一个脚本来从日志文件中获取某些文本并将其发布到html文件中.我遇到的问题是我希望grep的每个结果都在里面 p / p标签. 这是我到目前为止所拥有的: cat my.log | egrep 'someText|otherText' | sed 's/timestamp//' 解决方法 使用egrep和sed 你目
我正在编写一个脚本来从日志文件中获取某些文本并将其发布到html文件中.我遇到的问题是我希望grep的每个结果都在里面< p>< / p>标签.

这是我到目前为止所拥有的:

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

解决方法

使用egrep和sed

你目前有:

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

要在文本周围添加para-tags,只需在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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读