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.
This would be the resulting list:
text
words
123
How can I list all of the items appearing between parenthesis?
You can use
awklike this:awk -F "[()]" '{ for (i=2; i<NF; i+=2) print $i }' file.txtprints:
You can use an array to print the unique values:
awk -F "[()]" '{ for (i=2; i<NF; i+=2) array[$1]=$i; print array[$1] }' file.txtprints:
HTH