我有一个AWK这样的脚本,我将在一个文件上运行:如何限制awk只搜索某个HTML标签中包含的项目?
cat input.txt | awk 'gsub(/[^ ]*(fish|shark|whale)[^ ]*/,"(&)")' >> output.txt
这增加了括号包含文字“鱼”,“鲨鱼”的所有行,或“鲸鱼”,为如:
The whale asked the shark to swim elsewhere.
The fish were unhappy.
通过脚本运行它后,文件就变成了:
The (whale) asked the (shark) to swim elsewhere.
The (fish) were unhappy.
的文件标有HTML标签,我需要做的只是更换之间发生<b>
和</b>
标签。
The whale asked <b>the shark to swim</b> elsewhere.
<b>The fish were</b> unhappy.
这将成为:
The whale asked <b> the (shark) to swim </b> elsewhere.
<b> The (fish) were </b> unhappy.
- 匹配大胆的标签永远放在不同的行。起始
<b>
标记总是与结尾</b>
标记在同一行上。
我怎样才能限制awk
的搜索只搜索和修改<b>
和</b>
标签之间的文本?
上'匹配()'函数读向上及其相关AWK乏,RSTART和RLENGTH。祝你好运。 – shellter 2013-04-21 01:38:53
一个UUOC奖等着你。 – 2013-04-21 02:13:27