matching a pattern in thesaurus output
Saturday, 2 December 2017 08:26 amThere 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.
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.