I have never been able to find out how, when using 'sed', to limit changing the character case of a particular buffered output. For example, in the following 'sed' command I have two selected two spans of text to save as buffers to re-use during substition:

sed -ri 's/^<div class="line" data-line-mode="verse"><span class="speaker"[^>]*>([^<]*)<\/span>[ ]*(.*)[ ]*$/<p class="psi"><font size="-1" color="green"><b>\U\1<\/b>:<\/font><br>\n\2<br>/' "$f"

The desired output then is:

<p class="psi"><font size="-1" color="green"><b>FIRST_BUFFER_OUTPUT_ALL_UPPERCASE<\/b>:<\/font><br>\nSecond_buffer_output_originalCase<br>

But what I always end up with is:

<p class="psi"><font size="-1" color="green"><b>FIRST_BUFFER_OUTPUT_ALL_UPPERCASE<\/B>:<\/FONT><BR>\nSECOND_BUFFER_OUTPUT_ORIGINALCASE<BR>

So everything after the '\U\1' in the command gets its case altered to UPPERCASE, including tag chars. Is there a way to limit '\U\1' to altering only the contents of buffer '\1' to UPPERCASE, leaving everything else as typed?

有帮助吗?

解决方案

From this answer, try \E to stop case conversion started by \L or \U:

sed -ri 's/^...$/...\U\1\E<\/b>:<\/font><br>\n\2<br>/' "$f"
                         ^^
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top