Line-Oriented Command Pipelines

A line-oriented pipeline can filter or summarize rows as long as its tools agree on what a line and record mean.

Source
Anbloq
Language
English
Created
Updated
Chapters
4
Reading time
1 min
In this article4 chapters
  1. Trace a simple count
  2. Use a parser for multiline records
  3. Use test records that reveal what a line means
  4. Check whether the source is really one record per line

Trace a simple count

Given three lines containing A, B, A and ordinary terminators, filtering for A yields two line records. A prefix or exact match rule determines what qualifies.

Use a parser for multiline records

A quoted CSV field may contain an embedded line break. A row filter applied before CSV parsing can break that record. CSV line boundaries show when the raw line abstraction is insufficient.[1]

Use test records that reveal what a line means

A pipeline reads event lines, keeps those beginning with WARN and counts them. For WARN open, INFO WARN mentioned and WARN close the correct prefix count is two. Searching for the token anywhere would count all three. See prefix and suffix checks.

WARN open → keep
INFO WARN mentioned → skip
WARN close → keep
Output count: 2

Check whether the source is really one record per line

Quoted rows can contain several physical lines. Use a parser for those formats before applying record-level operations. Test an unterminated last line and blank input separately.

References

  1. The Open Group, POSIX Shell Command Language ↩