Premium lesson

Formatting the Output of Commands

Shell·3 min read·Jan 1, 2025

Software developers are often required to work with large datasets or files, such as CSVs or logs.

Rather than loading the entire data into memory, developers can filter out, narrow down, and transform output to only focus on relevant lines or sections, such as specific logs, function calls, errors, and so on.

Filtering output based on patterns

The grep command — which stands for global regular expression print — is used to filter the lines of any given input based on patterns:

$ grep [-i] [-v] pattern [file ...]

Where:

  • -i is an optional flag used to make grep case insensitive.

  • -v is an optional flag used to invert the search.

  • pattern is a string literal or a basic regular expression to find.

  • file ... is a list of file paths to read the content from.

icon light bulb key

Unlock the CLI & Scripting with Bash module

Learn how to gain advanced control over the OS and automate complex routine tasks prone to manual errors with the CLI and Bash scripting.

You get immediate access to:

  • 34 focused lessons across the CLI and Bash
  • 4 real-world projects with commented solutions
  • Ongoing updates to this bundle
  • Lifetime access to this bundle
Unlock this module