miriam english (miriam_e) wrote,
miriam english

matching a pattern in thesaurus output

There must be a simpler way to do this. I was looking for words similar in meaning to "back" or "previous" or "before" but beginning with the letter "d".

My awk is a bit rusty so I used sed, which I seem to use almost every day, wonderful, ugly command it is. Here is what I came up with:

dict -d moby-thesaurus back | sed -z 's/,/\n/g' | sed 's/^[[:space:]]*//' | sed -n '/^[dD]/p'

dict looks up "back" in "moby-thesaurus"
pipe to...
sed gulps it all down as a single line using the -z option and, for all commas, substitutes a newline
pipe to...
sed removes all whitespace characters from start of each line
pipe to...
sed prints only lines that start with "d" or "D"

The choice of pattern is important, for example '\<d' also finds multiple word results where one of the words starts with "d" (e.g. "lay down").

But there must be a simpler way. Jeez!
I can hardly wait for general purpose AI.

(Crossposted from https://miriam-e.dreamwidth.org/332278.html at my Dreamwidth account. Number of comments there so far: comment count unavailable)
  • Post a new comment


    default userpic

    Your reply will be screened

    Your IP address will be recorded 

    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.