문제

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