You can try this
sed -e 's/\(/\n\(/g' -e 's/\)/\n/g' filename|awk -F'(' '{print $2}'|sort -u
Explaination:
The first sed statement puts the words in brackets in a new line, and the second sed replaces the ')' character with a new line. So, after following the instructions below
sed -e 's/\(/\n\(/g' -e 's/\)/\n/g' filename
The output will look like this:
This is some (text .This (text has some (words in parenthesis. Sometimes, there are numbers, such as (123 in parenthesis too.
Now move this output below the awk statement, which prints the second word between the filter character '('
awk -F'(' '{print $2}'
the conclusion will now be
text text words 123
the above output is passed through the channel to sort the -u command to give unique words from the above output. Hope this explanation helps.
Venkat madhav
source share