Bash: html 标签内的大写文本与 sed
Bash: uppercase text inside html tag with sed
echo -e '<h1>abcd</h1>\n<h2>efgh</h2>' | sed 's#<h1>(.*?)<\h1>#<h1>\U&</h1>#g'
期望的输出是:
<h1>ABCD</h1>
<h2>efgh</h2>
有什么想法吗?谢谢
这仅适用于您的情况,不会解析 HTML。
DISCLAIMER
First read:
This parsing with a sed
Search-and-replace Regular Expression is a shortcut interpretation.
It is in no way for use in any kind of production setup; as it would break on so many valid HTML syntax or layout variations like: namespaces, multi-line, spacing, nesting, use of attributes, entities, CDATA…
sed -E 's#<h1>(.*)</h1>#<h1>\U\E</h1>#g' <<<$'<h1>abcd</h1>\n<h2>efgh</h2>'
基本上,它打开大写\U
,然后打印捕获的组1 </code>,然后关闭大写<code>\E
。
echo -e '<h1>abcd</h1>\n<h2>efgh</h2>' | sed 's#<h1>(.*?)<\h1>#<h1>\U&</h1>#g'
期望的输出是:
<h1>ABCD</h1>
<h2>efgh</h2>
有什么想法吗?谢谢
这仅适用于您的情况,不会解析 HTML。
DISCLAIMER
First read:
This parsing with a
sed
Search-and-replace Regular Expression is a shortcut interpretation.It is in no way for use in any kind of production setup; as it would break on so many valid HTML syntax or layout variations like: namespaces, multi-line, spacing, nesting, use of attributes, entities, CDATA…
sed -E 's#<h1>(.*)</h1>#<h1>\U\E</h1>#g' <<<$'<h1>abcd</h1>\n<h2>efgh</h2>'
基本上,它打开大写\U
,然后打印捕获的组1 </code>,然后关闭大写<code>\E
。