gpt4 book ai didi

linux - 获取引号之间的单词

转载 作者:IT王子 更新时间:2023-10-29 00:55:14 24 4
gpt4 key购买 nike

我有 x 行是这样的:

Unable to find latest released revision of 'CONTRIB_046578'.   

我需要提取 '' 之间的单词,在此示例中,单词 CONTRIB_046578,如果可能的话,计算数量使用 grepsed 或任何其他命令出现该词的次数?

最佳答案

最干净的解决方案是 grep -Po "(?<=')[^']+(?=')"

$ cat file
Unable to find latest released revision of 'CONTRIB_046578'
Unable to find latest released revision of 'foo'
Unable to find latest released revision of 'bar'
Unable to find latest released revision of 'CONTRIB_046578'

# Print occurences
$ grep -Po "(?<=')[^']+(?=')" file
CONTRIB_046578
foo
bar
CONTRIB_046578

# Count occurences
$ grep -Pc "(?<=')[^']+(?=')" file
4

# Count unique occurrences
$ grep -Po "(?<=')[^']+(?=')" file | sort | uniq -c
2 CONTRIB_046578
1 bar
1 foo

关于linux - 获取引号之间的单词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13990889/

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