Skip to content

find

find reads a text line by line and prints the one line that answers your question. It prints nothing when no line answers, and says not sure (unsure) when the best line falls short of the bar.

Terminal window
thinkthen find \
'Which line states the requested action?' message.txt

Output

Please refund my order.
message.txt
Morgan works for Example Group.
Please refund my order.

The second line asks for a refund, so find prints it.

Terminal window
echo 'Morgan works for Example Group.' |
thinkthen find 'Which line states the requested action?'

Output

(nothing printed)

Nothing: the text says who Morgan works for, and asks for nothing.

See why

--json prints the details. This jq keeps the line and its chance.

Terminal window
thinkthen find --json \
'Which line states the requested action?' message.txt |
jq -c '{text: .answer.text, probability}'

Output

{"text":"Please refund my order.","probability":0.77}

probability is the chance that this line answers the question. 0.77 reaches the bar of 0.5, so find prints the line. JSON output lists every field, including where the line starts and ends.

Raise the bar to 0.9 and find is not sure, because the line has 0.77.

Terminal window
thinkthen find --threshold 0.9 \
'Which line states the requested action?' message.txt

Output

unsure

Send not sure to a person. Never treat it as no line. The default bar is 0.5.

Use the answer in a script

--check turns the answer into the exit code, and the line still prints.

Terminal window
if action=$(thinkthen find --check \
'Which line states the requested action?' \
message.txt)
then
echo "to do: $action"
else
status=$?
case "$status" in
1|3) echo 'send to a person' ;;
*) exit "$status" ;;
esac
fi

Output

to do: Please refund my order.
Answer Exit code with --check
a line 0
no line 1
unsure 3

Without --check, find exits 0 whenever it answers. Exit codes lists every code.

Find a line in every row of a CSV file

Each cell can hold several lines, inside quotes.

messages.csv
id,text
b1,"Morgan works for Example Group.
Please refund my order."
b2,Morgan works for Example Group.
Terminal window
thinkthen find 'Which line states the requested action?' \
--from csv --column text --into action < messages.csv

Output

id,text,action
b1,"Morgan works for Example Group.
Please refund my order.",Please refund my order.
b2,Morgan works for Example Group.,

--column names the column to read, and --into names the new answer column. A row with no line gets an empty cell. File types covers TSV, Excel and other files.

Options
OptionWhat it does
<QUESTION>Question to ask
[FILE]...Input files; default: standard input
--name <NAME>Optional execution identity
--text <TEXT>Judge this text instead of reading input
--threshold <THRESHOLD>Required probability
--check [=<CHECK>]Return the verdict as an exit code
--column <COLUMN>Field column; repeat; replaces a saved pointer
--details [=<DETAILS>]Add status, probability, error, detail and source columns
--in-place [=<IN-PLACE>]Replace source with backup
--into <INTO>Answer field for JSON Lines; column for tables
--output <OUTPUT>Destination path
--sheet <SHEET>Worksheet

Shared options

If find can't answer a text, it prints an error and exits with code 2, 4, 5 or 6. Troubleshooting lists each error and its fix.

In code: Python · TypeScript · Go · Java · Kotlin · C# · R · Ruby · Rust · Swift · Zig · C · C++ · DuckDB · SQLite · PostgreSQL

Next: recognize picks out the names of people, companies and other kinds in a text.