Filter

Keep matching lines

Keep only log lines that contain error.

What this template solves

This template is useful when you want a narrow output file that keeps only lines matching one pattern such as error, timeout, hostname, or feature flag names.

Open the workspace with this template preloaded, then refine it for your own file and text pattern.

Sample input

info ok
error timeout
warn retry
error fatal

Prompt to start from

Keep only lines that contain error

Expected command

sed -n '/error/p'

Tags

filterlogspattern

Best for

  • Extract only error lines from a mixed application log.
  • Keep hostnames or domains that match one environment.
  • Create a small review file from a large text export.

How to use this template

  1. 1Identify the pattern you want to keep and make sure the match is specific enough.
  2. 2Use the template command as the base filter.
  3. 3Adjust the pattern in AskSed if you need stricter matching before saving the final command.

Template FAQ

Can sed keep only matching lines from a large file?

Yes. A pattern like `sed -n '/error/p'` prints only matching rows and suppresses everything else. This is useful when you want a focused output containing just one keyword or pattern.

What kinds of searches fit the keep-matching-lines template best?

It works well for extracting errors, hostnames, domains, timeout entries, feature flags, or any repeated token that should remain while unrelated lines are removed from the output.

Related templates

Explore nearby sed workflows that target similar replace, cleanup, filtering, or rewrite tasks.

Keep matching lines Sed Template | AskSed