将某些匹配项转换为大写的 Sed 表达式 [英] Sed expression that converts some matches to uppercase

查看:45
本文介绍了将某些匹配项转换为大写的 Sed 表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此 sed 表达式将输入字符串转换为两行输出字符串.两条输出行中的每一行都由输入的子串组成.第一行需要转换成大写:

This sed expression converts an input string into a two-line output string. Each of the two output lines are composed of substrings from the input. The first line needs to be convered into upper case:

s:random_stuff\(choice1\|choice2\){\([^}]*\)}:\U\1\n\2:

目的是转化

random_stuff_choice1{This is a sentence that MAY contain AnyThing}
random_stuff_choice2{This is another similar sentence}

进入

CHOICE1
This is a sentence that MAY contain AnyThing
CHOICE2
This is another similar sentence

我遇到的问题是 \U 适用于它后面的所有内容,因此第二行也是大写的.是否可以让 \U 仅适用于第一场比赛?

The problem I have is that \U aplies to everything following it so the second line is also uppercased. Is it possible to make \U apply to the first match only ?

推荐答案

使用\E取消\U:

s:random_stuff_\(choice1\|choice2\){\([^}]*\)}:\U\1\E\n\2:

这篇关于将某些匹配项转换为大写的 Sed 表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆