我有一个文件,其中包含括号中的一些单词。我想编制一个出现在那里的所有独特单词的列表,例如:
This is some (text).
This (text) has some (words) in parenthesis.
Sometimes, there are numbers, such as (123) in parenthesis too.
这将是结果列表:
text
words
123
如何列出括号内出现的所有项目?
您可以使用awk
像这样:
awk -F "[()]" '{ for (i=2; i<NF; i+=2) print $i }' file.txt
prints:
text
text
words
123
您可以使用数组来打印唯一值:
awk -F "[()]" '{ for (i=2; i<NF; i+=2) array[$1]=$i; print array[$1] }' file.txt
prints:
text
words
123
HTH
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)