Skip to tutorial content
Rate module Not yet rated

Pattern Operations: Match and Parse

4 min read
On this page

In this lesson, you will learn:

  • What the Match operation does
  • The Parse operations
  • When regular expressions help

πŸ” Quick look back: Last time: Variables, Attributes and Tables. You learned how pattern variables and tables fill CI attributes.

1 The Problem: Command Output Is Messy

Commands return lines of text. The version you want is buried in the middle:

  • Some lines are headers.
  • Values sit between other words.

🎯 The problem: Command output is messy, and you need one clean value.

πŸ‘‰ The fix: Use Match to check conditions and Parse to pull out just the value.

Table of operations.
Figure 1. Common pattern operations.

2 Parsing strategies

  • Delimited text: split on spaces or commas.
  • Regular expression: find text that fits a pattern.
  • Key and value: lines like version=4.2.

Key term: Regular expression

A short code that describes text to find, such as digits after ‘version’.

3 Match

Match checks a condition, such as ‘the OS is Linux’. If it’s false, the step stops or skips. This keeps a pattern from running on the wrong thing.

4 Project Clear View: How We Implemented It

πŸ“ Situation: The archiver pattern will need to pull its version from text.

🧭 Decision: Practise on a known value in the Linux pattern first.

πŸ› οΈ Steps we took:

  1. Found the step that parses the OS version on snwr-mail-01.
  2. Read its parsing strategy: a regular expression.
  3. Tried a key-and-value strategy on a sample line for comparison.
  4. Chose key-and-value for the archiver’s config file.

βœ… What we verified:

  • The team understands both strategies.
  • The archiver’s parsing approach is chosen.

πŸ“ Evidence: Parsing notes for the archiver pattern.

5 Quick recap

  • Match continues only when a condition is true.
  • Parse operations pull values from output, variables and files.
  • Strategies: delimited, regular expression, key and value.
  • Pick the simplest strategy that works.

6 Check yourself

Think of your answer first. Then tap to check.

1 What does Match do? Show answer

Continues only if a condition is true.

2 Which operation reads a file? Show answer

Parse File.

3 Which strategy did SNWR choose for the archiver’s config? Show answer

Key and value.

Nice work! You can pull clean values from messy output. πŸŽ‰
Next up: Debugging a Pattern

Was this lesson helpful?

Have a question or doubt?

Ask here and get help from instructors and fellow learners.

0 / 300

Only logged-in learners can post.