如何找到括号之间出现的所有单词? [英] How to find all words appearing between parenthesis?

查看:118
本文介绍了如何找到括号之间出现的所有单词?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含在括号一些字的文件。我想编译所有的出现在那里,例如独特的单词的列表:

I have a file containing some words in parenthesis. I'd like to compile a list of all of the unique words appearing there, e.g.:

This is some (text).
This (text) has some (words) in parenthesis.
Sometimes, there are numbers, such as (123) in parenthesis too.

这是结果列表:

text
words
123

我怎么能列出所有括号之间出现的项目?

How can I list all of the items appearing between parenthesis?

推荐答案

您可以使用 AWK 是这样的:

的awk -F[()]'{为(i = 2; I< NF;我+ = 2)打印$ I}'file.txt的

打印:

text
text
words
123

您可以使用一个数组来打印唯一值:

You can use an array to print the unique values:

的awk -F[()]'{为(i = 2; I< NF;我+ = 2)数组[$ 1] = $ I;打印数组[$ 1]}'file.txt的

打印:

text
words
123

心连心

这篇关于如何找到括号之间出现的所有单词?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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