Regex 使用sed删除行的开头,直到单词大写

Regex 使用sed删除行的开头,直到单词大写,regex,sed,regex-greedy,Regex,Sed,Regex Greedy,我试图使用sed删除许多行的开头。目标是删除每行中的所有字符,直到一个单词包含两个连续的大写字母 输入将始终类似于: 1 where did you get ACQUIRE, obtain, come by, receive, gain, earn, win, come into, take 2 I got your letter: RECEIVE, be sent, be in receipt of, be given. 3 your tea is getting cold: BECOME,

我试图使用sed删除许多行的开头。目标是删除每行中的所有字符,直到一个单词包含两个连续的大写字母

输入将始终类似于:

1 where did you get ACQUIRE, obtain, come by, receive, gain, earn, win, come into, take 
2 I got your letter: RECEIVE, be sent, be in receipt of, be given.
3 your tea is getting cold: BECOME, grow, turn, go.
4 get the children from school: FETCH, collect, go for, call for, pick up, bring, deliver, convey, ferry, transport.
5 the chairman gets £650,000 a year: EARN, be paid, take home, bring in, make, receive, collect, gross; informal pocket, bank, rake in, net, bag.
6 have the police got their man?: APPREHEND, catch.
我希望输出是:

ACQUIRE, obtain, come by, receive, gain, earn, win, come into, take 
RECEIVE, be sent, be in receipt of, be given.
BECOME, grow, turn, go.
FETCH, collect, go for, call for, pick up, bring, deliver, convey, ferry, transport.
EARN, be paid, take home, bring in, make, receive, collect, gross; informal pocket, bank, rake in, net, bag.
APPREHEND, catch.
我要建造这个:

sed -n 's/^.*[A-Z]\{2\}//p'
但是这个表达式也删除了大写的单词。你知道怎么做吗

问题在于缺乏前瞻性和非贪婪的选择。解决这个问题的一个方法是做两次替换。第一种方法获取所需的文本,将其保存为组1,并将其附加在换行符之后,然后删除所有数据,直到该换行符出现,如下所示:

sed 's/\([A-Z]\{2,\}.*\)/\n\1/; s/[^\n]*\n//' infile
它产生:

ACQUIRE, obtain, come by, receive, gain, earn, win, come into, take 
RECEIVE, be sent, be in receipt of, be given.
BECOME, grow, turn, go.
FETCH, collect, go for, call for, pick up, bring, deliver, convey, ferry, transport.
EARN, be paid, take home, bring in, make, receive, collect, gross; informal pocket, bank, rake in, net, bag.
APPREHEND, catch.

这应该在
awk
中起作用,但它在
5行上给出了错误的输出

awk '{print substr($0,match($0,/[[:upper:]][[:upper:]]/))}' file
ACQUIRE, obtain, come by, receive, gain, earn, win, come into, take
RECEIVE, be sent, be in receipt of, be given.
BECOME, grow, turn, go.
FETCH, collect, go for, call for, pick up, bring, deliver, convey, ferry, transport.
5 the chairman gets
APPREHEND, catch.
match
查找第一行的两个大写字母,然后
substr
使用它打印行的最后一部分