gpt4 book ai didi

将某些匹配项转换为大写的 Sed 表达式

转载 作者:行者123 更新时间:2023-12-04 23:24:29 28 4
gpt4 key购买 nike

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

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 仅适用于第一场比赛?

最佳答案

sed :

$ sed 's/.*\(choice[0-9]\+\){\([^}]*\)}/\U\1\n\E\2/' file
CHOICE1
This is a sentence that MAY contain AnyThing
CHOICE2
This is another similar sentence

awk :

$ awk -F'{|}' 'gsub(/.*_/,""){print toupper($1)"\n"$2}' file
CHOICE1
This is a sentence that MAY contain AnyThing
CHOICE2
This is another similar sentence

关于将某些匹配项转换为大写的 Sed 表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15137059/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com