# Search

TKTail searches without loading files into memory and without freezing the window - also a file of many
gigabytes. Which search to use:

| You want | Use |
|---|---|
| The next place in this file | **Find** - Ctrl+F (below) |
| Every match in all open files and event logs | **Find in All Open Files** - Ctrl+Shift+F, or the search box on the right of the toolbar |
| Text, a field condition, a time range - in chosen files, folders or event logs | **Advanced Search** - Ctrl+Alt+F ([Advanced Search](https://tktail.dev/help/bottom-panel/#advanced-search)) |
| Only among the results of a search | **Search Within These Results** ([Search Results](https://tktail.dev/help/bottom-panel/#search-results)) |
| One thing, then another within a time window ("a WARN, then an ERROR within 30 s") | a **sequence** in Advanced Search ([Sequences](https://tktail.dev/help/bottom-panel/#sequences-one-thing-then-another-in-time)) |
| Files by name or content in a folder - without opening them | the Explorer's **Search Files...** / **Search Contents...** ([Searching folders](https://tktail.dev/help/explorer/#searching-folders)) |
| Events in an event log | Find in an event tab ([Finding events](https://tktail.dev/help/windows-event-log/#finding-events)) |
| The same question again later | a **Saved Search** ([Save the question, save the answer](https://tktail.dev/help/bottom-panel/#save-the-question-save-the-answer)) |
| The results kept across a restart, or kept before the log rotates | **Pin Search**, then **Save as Evidence** ([Rotating logs: pin, then save](https://tktail.dev/help/saving-evidence/#rotating-logs-pin-then-save)) |
| An AI assistant to search for you - and to summarize what it finds (the top 10 client IPs, requests per minute, average times) | [AI assistance](https://tktail.dev/help/ai-assistance/#search-and-summaries) - its searches show in Search Results too |

Every search except Find keeps its results as a **search session** in the bottom panel's
[Search Results](https://tktail.dev/help/bottom-panel/#search-results): you can open each result, refine, export or save it, and
run it again later. A search says exactly what it searched and whether everything was searched
(*Completed*, *Incomplete* with the reason, *Cancelled*).

## Find in a file

**Ctrl+F** opens the find bar directly below the tabs of the pane you are working in; it
searches **only the current file** (the toolbar's search box searches open files or folders).

*Screenshot: The find bar below the tabs: the third of 3,747 matches*

- Type and press **Enter** (next) or **Shift+Enter** (previous), or use the up / down arrows;
  **F3** / **Shift+F3** work from the pane too. **Esc** or **x** closes the bar - the search
  stays with the file.
- Options (the small buttons): **Aa** match case, **.\*** regular expression, the funnel for a
  field condition such as `level = ERROR` in structured records, and the circular arrows for
  wrapping around at the end of the file.
- Next to the query the bar shows where you are, for example **3 / 864** (the third of 864
  matches). The total is counted in the background after the first match is found
  ("counting 42%" meanwhile), so even huge files never freeze. With more than 100,000 matches
  the bar shows only the total. **No matches** means the file does not contain it.
- Every tab keeps its own search: switching tabs shows that tab's query and result; a tab
  without a search keeps what you typed, so Enter repeats it there. In a split, the bar moves
  to the pane you click into.
- The search runs in the background in slices, so it never freezes the window, even on huge
  files; the result is highlighted and scrolled into view (the view pauses).
- Previous searches are kept in the find history.

## Regular expressions

With **.\*** on, the query is a regular expression - the same rules everywhere TKTail searches:
the find bar, Find in All Open Files, Advanced Search, event tabs, alert rules and the export
filter.

- **Any language.** Letters, digits and case work for every script: with **Aa** off,
  `zamówienie` finds `ZAMÓWIENIE` and `Zamówienie`; `.` is one whole character, an emoji too;
  `\d`, `\w` and `\s` include non-Latin digits, letters and spaces (use `[0-9]` for ASCII digits
  only).
- **One line at a time.** A match never runs across lines; `^` and `$` are the start and the end
  of the line. In a log whose entries span several lines (a stack trace), the line that matches
  is found and the Inspector / RECORD show the whole entry.
- **Useful additions:** look behind `(?<=\$)\d+` (a number after `$`), named groups
  `(?<year>\d{4})`, Unicode classes `\p{L}` (any letter), `(?i)` for case-insensitive, `\x{F3}`
  for a character by its code. Older patterns with `\u` and four hex digits (`\u00F3`) still work.
- **Patterns that would run away** (`(a+)+$` on a long line) stop at once at that line. TKTail
  has two safety layers: each line has a fixed limit, and a whole search has a breaker. In the
  find bar, Find Next ends with *Regex complexity limit exceeded on a line - simplify the
  pattern*, and a count that stopped there says so - *1 / 2 · incomplete* (point at it for the
  reason). A search over sources (Find in All Open Files, Advanced Search) skips such a line, keeps
  going and says *Incomplete - 1 line skipped*; a pattern that keeps hitting the limit is stopped -
  *This regular expression is too expensive for the data searched - simplify the pattern* - and
  what it found stays. That is not a syntax error: the same pattern may be fine on other data.
  Exporting the lines matching such a pattern fails rather than leave lines out. A mistake in the
  pattern
  says where it is: *Invalid regular expression at position 4: missing closing parenthesis*.
  When the find bar cuts a message short, point at it to read all of it.
- Searching for text that is not a regular expression is faster with **.\*** off.

## Recipes

**Search across several files** - open them (or drop them into TKTail), press **Ctrl+Shift+F**, type the
text and press Enter. The results list each match with its file, line and time; double-click one to go
there.

**Errors of one request across logs** - **Advanced Search** (Ctrl+Alt+F): add the files, a field condition
`requestId = ABC123` (or the text), a time range if you know it; **Search**.

**What happened right before an error** - a **sequence**: step 1 `WARN`, step 2 `ERROR` within 30 seconds after
it - see [Sequences](https://tktail.dev/help/bottom-panel/#sequences-one-thing-then-another-in-time).

**A folder of old logs** - in the Explorer, right-click the folder > **Search Contents...** - the files are read
without being opened as tabs.

## Search reference

Everything TKTail can search, in one table - the pages linked hold the details.

| | What TKTail offers |
|---|---|
| **Where** | the current file (Find); all open files and event logs (Find in All Open Files); chosen sources - up to 16 open files, event logs or folders, with subfolders and `;`-separated Include / Exclude masks (Advanced Search); the results of an earlier search (Search Within). Files on network shares like local ones. Folder searches read files without opening them (up to 10,000 per search) and skip binary files. |
| **Text** | literal text, or a [regular expression](https://tktail.dev/help/search/#regular-expressions) (TKTail Regex v1), each line tested on its own; **Aa** matches case. |
| **Fields** | `field = value` and `!=`, `>`, `>=`, `<`, `<=`, `contains`, `startswith`, `endswith`, `exists`, `missing`, `is null`, `is not null`. A field is named by its name, a dotted JSON path, a FIX tag or name, an HL7 reference (`PID-3`) or a role (`severity`, `timestamp`, `message` ...). Numbers compare as numbers, severities on the syslog scale (`severity <= error`). Formats with fields: [Built-in formats](https://tktail.dev/help/built-in-formats/), and [your own](https://tktail.dev/help/custom-formats/). |
| **Time** | any time, the last 15 minutes / hour / 24 hours, today, or between two times; each record by its own time ([Advanced Search](https://tktail.dev/help/bottom-panel/#advanced-search)). Go To a time: Ctrl+Shift+G ([Viewing logs](https://tktail.dev/help/viewing-logs/)). |
| **Combine** | all of / any of, groups inside groups (up to 32 conditions and groups, 4 levels), conditions per source ([The builder](https://tktail.dev/help/bottom-panel/#the-builder-several-sources-and--or)). |
| **Event logs** | in Find in All Open Files, Advanced Search and sequences, with the fields time, level, provider, event ID, record ID and message; Find in an event tab looks at the message, provider, event ID and level ([Finding events](https://tktail.dev/help/windows-event-log/#finding-events)). |
| **Sequences** | Temporal Search: 2 to 8 steps, each within a time after the one before (up to a day), joined by time only or by a key such as a request ID - across files, folders and event logs ([Sequences](https://tktail.dev/help/bottom-panel/#sequences-one-thing-then-another-in-time)). |
| **Results** | a search session in Search Results: every match with its source, line and time; Completed, Incomplete (with the reason) or Cancelled; Search Within; Run Again; export as TSV, CSV or JSON Lines ([Search Results](https://tktail.dev/help/bottom-panel/#search-results)). |
| **Keep** | Saved Searches (the question, also as a `.tktsearch.json` file) and saved results (the answer, a `.tktresults` file) ([Save the question, save the answer](https://tktail.dev/help/bottom-panel/#save-the-question-save-the-answer)). |
| **Command line** | `tktail open <file> --search <text> [--regex] [--case-sensitive]`; `tktail folder <path> --search-files <name>` or `--search-content <text> [--recursive]` - the search runs in the window ([Command line](https://tktail.dev/help/command-line/)). |

---

The HTML page: https://tktail.dev/help/search/
