I am trying to write a simple script in bash to query the LibreOffice thesaurus extension as a text file. For each input query string, I want the output to be all the related strings. And I want to do this in bash.

To download and extract the thesaurus, I do

```
wget "https://extensions.libreoffice.org/assets/downloads/41/1653961771/dict-en-20220601_lo.oxt" # download LO dictionary & thesaurus

unzip -p dict-en-20220601_lo.oxt th_en_US_v2.dat > lo # extract contents of thesaurus to text file

```

Taking a look at part of the text file:

```
nine|3
(adj)|9|ix|cardinal (similar term)
(noun)|9|IX|niner|Nina from Carolina|ennead|digit (generic term)|figure (generic term)
(noun)|baseball club|ball club|club|baseball team (generic term)
nine-banded armadillo|1
(noun)|peba|Texas armadillo|Dasypus novemcinctus|armadillo (generic term)
nine-fold|1
(adj)|nonuple|ninefold|multiple (similar term)
nine-membered|1
(adj)|9-membered|membered (similar term)
nine-sided|1
(adj)|multilateral (similar term)|many-sided (similar term)
nine-spot|1
(noun)|spot (generic term)

```

So for example, I want to be able input
"nine" as a query and have bash return something like

```
9
ix
cardinal
9
IX
niner
Nina from Carolina
ennead
digit
figure
baseball club
ball club
club
baseball team

```

I think this should be fairly easy to do using the right syntax with `awk` or `sed`, especially since all of the lines containing query terms do NOT begin with "(" and all of the line containing related terms DO begin with "(".

But I'm still somewhat of a newbie, and haven't been able to figure it out yet. The crux of the matter for me seems to be getting the query term and all related terms onto a single line. From there, I know how to `sed` my way to victory. But getting to that point has proven challenging for me.

TIA for your help!

p.s. I'm trying to do something similar to this, but my situation is a little different, and I don't understand the syntax well enough to modify it for my needs: <https://www.unix.com/unix-for-dummies-questions-and-answers/184649-sed-join-lines-do-not-match-pattern.html>